When should Q_OBJECT be used?

前端 未结 4 2296
名媛妹妹
名媛妹妹 2020-11-27 16:51

The documentation states that:

The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and sl

4条回答
  •  眼角桃花
    2020-11-27 17:35

    Well the first part is pretty clear as you probably already know.. signals and slots, the rest of the Meta-object system is a little lesser known. Perhaps one of the more useful features is dynamic properties. Although these have many uses, I used them to take advantage of Qt's animation system QPropertyAnimation.

    There's a little more info about the meta-object system here: http://doc.qt.io/archives/4.6/metaobjects.html

    I think the bottom line is, if you inherit from the QObject hierarchy, throw in the Q_OBJECT macro regardless. It's simple to do and will save you from some potentially baffling problems down the road.

提交回复
热议问题