QT中添加Q_OBJECT出现的问题
2010-10-11 11:25
288 查看
我在用class My_Node : public QGraphicsItem,public QObject来生成自己的类时,想使用信号和槽机制,但这是dys_node.h中没有Q_OBJECT,不能使用信号槽。我将Q_OBJECT加上之后,出现几个不知道是什么的错误。然后我将工程目录下的Makefile删除,然后重新编译、链接文件,刚才的错误消失了,但出现如下三个错误:
error: 'staticMetaObject' is not a member of 'QGraphicsItem'
error: 'qt_metacast' is not a member of 'QGraphicsItem'
error: 'qt_metacall' is not a member of 'QGraphicsItem'
通过google,我发现这个错误是由于没有继承QObject类而引起的,但是我已经继承了QObject类了啊,到底是怎么回事呢?
最后终于在网上找到了答案,当多继承的时候,要将QObject放在前面,即将类的声明改为
class My_Node : public QObject,public QGraphicsItem
问题就解决了!!!
下面是我从网络上找到的说明原文:
Just got this error message while compiling a tiny class that derives from QTreeWidgetItem:
error C2039: 'staticMetaObject' : is not a member of 'QTreeWidgetItem'
What this is saying is that QTreeWidgetItem does not inherit from QObject, meaning that your own, singly-inherited class also does not inherit from QObject. Inheriting from QObject is one of the prerequisites to using the Q_OBJECT macro, which, if you’re anything like me, you automatically insert into any Qt GUI related class.
If you’re not using any of the meta object stuff in your subclass, such as signals/slots or properties, just take out the Q_OBJECT macro. If you need to use signals and slots, you’ll need to make your subclass multiply-inherit from QObject as well. If you take this route, remember that “Multiple Inheritance Requires QObject to Be First”, otherwise you’ll get either the same error as above, or something along the lines of “YourClass inherits from two QObject subclasses” from the moc。
error: 'staticMetaObject' is not a member of 'QGraphicsItem'
error: 'qt_metacast' is not a member of 'QGraphicsItem'
error: 'qt_metacall' is not a member of 'QGraphicsItem'
通过google,我发现这个错误是由于没有继承QObject类而引起的,但是我已经继承了QObject类了啊,到底是怎么回事呢?
最后终于在网上找到了答案,当多继承的时候,要将QObject放在前面,即将类的声明改为
class My_Node : public QObject,public QGraphicsItem
问题就解决了!!!
下面是我从网络上找到的说明原文:
Just got this error message while compiling a tiny class that derives from QTreeWidgetItem:
error C2039: 'staticMetaObject' : is not a member of 'QTreeWidgetItem'
What this is saying is that QTreeWidgetItem does not inherit from QObject, meaning that your own, singly-inherited class also does not inherit from QObject. Inheriting from QObject is one of the prerequisites to using the Q_OBJECT macro, which, if you’re anything like me, you automatically insert into any Qt GUI related class.
If you’re not using any of the meta object stuff in your subclass, such as signals/slots or properties, just take out the Q_OBJECT macro. If you need to use signals and slots, you’ll need to make your subclass multiply-inherit from QObject as well. If you take this route, remember that “Multiple Inheritance Requires QObject to Be First”, otherwise you’ll get either the same error as above, or something along the lines of “YourClass inherits from two QObject subclasses” from the moc。
相关文章推荐
- QT中添加Q_OBJECT出现的问题
- QT中添加Q_OBJECT出现的问题 & Qt moc: error C2039
- QT中添加Q_OBJECT出现的问题
- QT中添加Q_OBJECT和继承QObject出现的问题
- QT中添加Q_OBJECT出现的问题
- QT中添加Q_OBJECT出现的问题
- 在QT添加QWebView是出现的问题
- Qt中在QMAinWindow内添加layout出现问题
- QT添加rtmp库的时候出现问题
- php中出现“Call to a member function Execute() on a non-object”的问题
- caffe SSD 添加新层时出现的问题
- 解决busybox添加用户出现passwd: unknown uid 0的问题
- 关于QT中自动添加槽函数编译出错的问题
- Oracle导出Excel时怎么避免出现添加引号、字段前面去0等问题
- Qt学习(复制linux在虚拟机中出现的问题)
- 【游戏开发备注之一】关于Cocos2dx_v1.x版本iphone与Android运行出现图片白块、添加GameCenter报错问题及编译Android闪退的解决办法&&CCLOG与CClog的区别
- centos下安装QT,出现无法安装libX11的问题
- fedora 18~20 中Qt 5.2.1 解决连接mysql数据库出现QMYSQL driver not loaded的问题
- Qt出现No such slot问题
- 界面中有UITableView时添加手势出现问题怎么办