Qt--QGraphicsItem 子類中使用信號與槽

最近,在使用Qt作一個小軟件,其中用到了QGraphicsItem,而且須要使用信號與槽機制.QGraphiIcs的子類要實現信號與槽機制須要繼承QObject.spa

class Node : public QObject,public QGraphicsItem {
Q_OBJECT      
....
}

注意:必定要將public QObject放在public QGraphicsItem的前面,而且在該類的定義中添加Q_OBJECT宏.code


編譯時出現警告 Warning: Class Node implements the interface QGraphicsItem but does not list it in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!繼承

在類的聲明中添加:Q_INTERFACES(QGraphicsItem)可解決該問題.it

相關文章
相關標籤/搜索