Getting to know Qt's property system
Qt's property system is similar to some other compiler vendors. However, it provides a cross-platform advantage and works with standard compilers supported by Qt on different platforms. To add a property, you must add the Q_PROPERTY()
macro to the QObject
derived class. This property acts like a class data member, but it provides extra features that are available through the Meta-Object System. A simple syntax looks as follows:
Q_PROPERTY(type variableName READ getterFunction WRITE setterFunction NOTIFY signalName)
In the preceding syntax, we used some of the most common parameters. But there are more parameters that are supported in the syntax. You can find out more by reading the Qt documentation. Let's have a look at the following code snippet, which uses the MEMBER
parameter:
Q_PROPERTY(QString text MEMBER m_text...