Qt Properties ‐ Basics - ProjectStow/ClassExamples GitHub Wiki

The Qt Property system is usable for all classes that inherit for QObject. The primary Qt for properties can be found at Qt Properties

The primary way that properties are implemented is via the use of the Q_PROPERTY macro in the header file for the class.

The generic form of the Macro is:

Q_PROPERTY(type name ... options)

where:

  • type is the data type of the property.
  • name is the name of the property.
  • options will be detailed at bit later.

Properties may either solely implemented as functions or as members optionally supported by functions.

When binding a property directly to a member variable then the macro must include the "MEMBER" option followed by the member name as defined in the class. For example:

    ...
    Q_PROPERTY(QString text MEMBER m_text)
    ...
 private:
    QString m_text;

The above example would allow read and write access to the member "text" via the property system, not directly to m_text.

If not directly binding to a member variable (recommend) the the option "READ" is required and should be followed by the name of the accessor method to read the property. The READ accessor method must either return the type as specified in the macro or a const reference to the type.

.... More to follow

Related Topics

  • Signals and Slots
  • Bindable
  • Dynamic Properties