Q_PROPERTY in Qt?

2019-06-16 17:13发布

问题:

I cant really figure out why do I need it, Been reading: http://doc.qt.io/qt-4.8/properties.html#requirements-for-declaring-properties

still cant really understand the use of it. any kind of help would be great!

回答1:

Read about the Qt Property System , this is just like a usual class method but it can be used with Qt's meta-object system:

 QPushButton *button = new QPushButton;
 QObject *object = button;

 button->setDown(true);
 object->setProperty("down", true);

Also these properties will be visible under Qt Designer too so you could create a custom widget with some properties and hook it up in Qt Designer, see this article for details.



回答2:

Properties help in RTTI like implementation using Qt's Meta object system.