Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QDeclarativeProperty Class Reference

The QDeclarativeProperty class abstracts accessing properties on objects created from QML. More...

 #include <QDeclarativeProperty>

This class was introduced in Qt 4.7.

Public Types

enum PropertyTypeCategory { InvalidCategory, List, Object, Normal }
enum Type { Invalid, Property, SignalProperty }

Public Functions

QDeclarativeProperty ()
QDeclarativeProperty ( QObject * obj )
QDeclarativeProperty ( QObject * obj, QDeclarativeContext * ctxt )
QDeclarativeProperty ( QObject * obj, QDeclarativeEngine * engine )
QDeclarativeProperty ( QObject * obj, const QString & name )
QDeclarativeProperty ( QObject * obj, const QString & name, QDeclarativeContext * ctxt )
QDeclarativeProperty ( QObject * obj, const QString & name, QDeclarativeEngine * engine )
QDeclarativeProperty ( const QDeclarativeProperty & other )
bool connectNotifySignal ( QObject * dest, const char * slot ) const
bool connectNotifySignal ( QObject * dest, int method ) const
bool hasNotifySignal () const
int index () const
bool isDesignable () const
bool isProperty () const
bool isResettable () const
bool isSignalProperty () const
bool isValid () const
bool isWritable () const
QMetaMethod method () const
QString name () const
bool needsNotifySignal () const
QObject * object () const
QMetaProperty property () const
int propertyType () const
PropertyTypeCategory propertyTypeCategory () const
const char * propertyTypeName () const
QVariant read () const
bool reset () const
Type type () const
bool write ( const QVariant & value ) const
QDeclarativeProperty & operator= ( const QDeclarativeProperty & other )
bool operator== ( const QDeclarativeProperty & other ) const

Static Public Members

QVariant read ( QObject * object, const QString & name )
QVariant read ( QObject * object, const QString & name, QDeclarativeContext * ctxt )
QVariant read ( QObject * object, const QString & name, QDeclarativeEngine * engine )
bool write ( QObject * object, const QString & name, const QVariant & value )
bool write ( QObject * object, const QString & name, const QVariant & value, QDeclarativeContext * ctxt )
bool write ( QObject * object, const QString & name, const QVariant & value, QDeclarativeEngine * engine )

Detailed Description

The QDeclarativeProperty class abstracts accessing properties on objects created from QML.

As QML uses Qt's meta-type system all of the existing QMetaObject classes can be used to introspect and interact with objects created by QML. However, some of the new features provided by QML - such as type safety and attached properties - are most easily used through the QDeclarativeProperty class that simplifies some of their natural complexity.

Unlike QMetaProperty which represents a property on a class type, QDeclarativeProperty encapsulates a property on a specific object instance. To read a property's value, programmers create a QDeclarativeProperty instance and call the read() method. Likewise to write a property value the write() method is used.

For example, for the following QML code:

 // MyItem.qml
 import QtQuick 1.0

 Text { text: "A bit of text" }

The Text object's properties could be accessed using QDeclarativeProperty, like this:

 #include <QDeclarativeProperty>
 #include <QGraphicsObject>

 ...

 QDeclarativeView view(QUrl::fromLocalFile("MyItem.qml"));
 QDeclarativeProperty property(view.rootObject(), "font.pixelSize");
 qWarning() << "Current pixel size:" << property.read().toInt();
 property.write(24);
 qWarning() << "Pixel size should now be 24:" << property.read().toInt();

Member Type Documentation

enum QDeclarativeProperty::PropertyTypeCategory

This enum specifies a category of QML property.

ConstantValueDescription
QDeclarativeProperty::InvalidCategory0The property is invalid, or is a signal property.
QDeclarativeProperty::List1The property is a QDeclarativeListProperty list property
QDeclarativeProperty::Object2The property is a QObject derived type pointer
QDeclarativeProperty::Normal3The property is a normal value property.

enum QDeclarativeProperty::Type

This enum specifies a type of QML property.

ConstantValueDescription
QDeclarativeProperty::Invalid0The property is invalid.
QDeclarativeProperty::Property1The property is a regular Qt property.
QDeclarativeProperty::SignalProperty2The property is a signal property.

Member Function Documentation

QDeclarativeProperty::QDeclarativeProperty ()

Create an invalid QDeclarativeProperty.

QDeclarativeProperty::QDeclarativeProperty ( QObject * obj )

Creates a QDeclarativeProperty for the default property of obj. If there is no default property, an invalid QDeclarativeProperty will be created.

QDeclarativeProperty::QDeclarativeProperty ( QObject * obj, QDeclarativeContext * ctxt )

Creates a QDeclarativeProperty for the default property of obj using the context ctxt. If there is no default property, an invalid QDeclarativeProperty will be created.

QDeclarativeProperty::QDeclarativeProperty ( QObject * obj, QDeclarativeEngine * engine )

Creates a QDeclarativeProperty for the default property of obj using the environment for instantiating QML components that is provided by engine. If there is no default property, an invalid QDeclarativeProperty will be created.

QDeclarativeProperty::QDeclarativeProperty ( QObject * obj, const QString & name )

Creates a QDeclarativeProperty for the property name of obj.

QDeclarativeProperty::QDeclarativeProperty ( QObject * obj, const QString & name, QDeclarativeContext * ctxt )

Creates a QDeclarativeProperty for the property name of obj using the context ctxt.

QDeclarativeProperty::QDeclarativeProperty ( QObject * obj, const QString & name, QDeclarativeEngine * engine )

Creates a QDeclarativeProperty for the property name of obj using the environment for instantiating QML components that is provided by engine.

QDeclarativeProperty::QDeclarativeProperty ( const QDeclarativeProperty & other )

Create a copy of other.

bool QDeclarativeProperty::connectNotifySignal ( QObject * dest, const char * slot ) const

Connects the property's change notifier signal to the specified slot of the dest object and returns true. Returns false if this metaproperty does not represent a regular Qt property or if it has no change notifier signal, or if the dest object does not have the specified slot.

bool QDeclarativeProperty::connectNotifySignal ( QObject * dest, int method ) const

Connects the property's change notifier signal to the specified method of the dest object and returns true. Returns false if this metaproperty does not represent a regular Qt property or if it has no change notifier signal, or if the dest object does not have the specified method.

bool QDeclarativeProperty::hasNotifySignal () const

Returns true if the property has a change notifier signal, otherwise false.

int QDeclarativeProperty::index () const

Return the Qt metaobject index of the property.

bool QDeclarativeProperty::isDesignable () const

Returns true if the property is designable, otherwise false.

bool QDeclarativeProperty::isProperty () const

Returns true if this QDeclarativeProperty represents a regular Qt property.

bool QDeclarativeProperty::isResettable () const

Returns true if the property is resettable, otherwise false.

bool QDeclarativeProperty::isSignalProperty () const

Returns true if this QDeclarativeProperty represents a QML signal property.

bool QDeclarativeProperty::isValid () const

Returns true if the QDeclarativeProperty refers to a valid property, otherwise false.

bool QDeclarativeProperty::isWritable () const

Returns true if the property is writable, otherwise false.

QMetaMethod QDeclarativeProperty::method () const

Return the QMetaMethod for this property if it is a SignalProperty, otherwise returns an invalid QMetaMethod.

QString QDeclarativeProperty::name () const

Return the name of this QML property.

bool QDeclarativeProperty::needsNotifySignal () const

Returns true if the property needs a change notifier signal for bindings to remain upto date, false otherwise.

Some properties, such as attached properties or those whose value never changes, do not require a change notifier.

QObject * QDeclarativeProperty::object () const

Returns the QDeclarativeProperty's QObject.

QMetaProperty QDeclarativeProperty::property () const

Returns the Qt property associated with this QML property.

int QDeclarativeProperty::propertyType () const

Returns the QVariant type of the property, or QVariant::Invalid if the property has no QVariant type.

PropertyTypeCategory QDeclarativeProperty::propertyTypeCategory () const

Returns the property category.

const char * QDeclarativeProperty::propertyTypeName () const

Returns the type name of the property, or 0 if the property has no type name.

QVariant QDeclarativeProperty::read () const

Returns the property value.

QVariant QDeclarativeProperty::read ( QObject * object, const QString & name ) [static]

Return the name property value of object. This method is equivalent to:

 QDeclarativeProperty p(object, name);
 p.read();

QVariant QDeclarativeProperty::read ( QObject * object, const QString & name, QDeclarativeContext * ctxt ) [static]

Return the name property value of object using the context ctxt. This method is equivalent to:

 QDeclarativeProperty p(object, name, context);
 p.read();

QVariant QDeclarativeProperty::read ( QObject * object, const QString & name, QDeclarativeEngine * engine ) [static]

Return the name property value of object using the environment for instantiating QML components that is provided by engine. . This method is equivalent to:

 QDeclarativeProperty p(object, name, engine);
 p.read();

bool QDeclarativeProperty::reset () const

Resets the property and returns true if the property is resettable. If the property is not resettable, nothing happens and false is returned.

Type QDeclarativeProperty::type () const

Returns the type of the property.

bool QDeclarativeProperty::write ( const QVariant & value ) const

Sets the property value to value and returns true. Returns false if the property can't be set because the value is the wrong type, for example.

bool QDeclarativeProperty::write ( QObject * object, const QString & name, const QVariant & value ) [static]

Writes value to the name property of object. This method is equivalent to:

 QDeclarativeProperty p(object, name);
 p.write(value);

bool QDeclarativeProperty::write ( QObject * object, const QString & name, const QVariant & value, QDeclarativeContext * ctxt ) [static]

Writes value to the name property of object using the context ctxt. This method is equivalent to:

 QDeclarativeProperty p(object, name, ctxt);
 p.write(value);

bool QDeclarativeProperty::write ( QObject * object, const QString & name, const QVariant & value, QDeclarativeEngine * engine ) [static]

Writes value to the name property of object using the environment for instantiating QML components that is provided by engine. This method is equivalent to:

 QDeclarativeProperty p(object, name, engine);
 p.write(value);

QDeclarativeProperty & QDeclarativeProperty::operator= ( const QDeclarativeProperty & other )

Assign other to this QDeclarativeProperty.

bool QDeclarativeProperty::operator== ( const QDeclarativeProperty & other ) const

Returns true if other and this QDeclarativeProperty represent the same property.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 85
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Quarterly au hasard

Logo

Traduction dynamique

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.7-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web