QT编译出错in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!
2013-12-13 11:24
423 查看
最近在看QT中图形视图。自己模仿着写了个小例子。由于功能需要,所以要添加信号槽,于是自己就动手添加起来。在
添加的过程中遇到了许多问题,现总结如下:
1.要自定义添加信号槽必须要继承QObject。
2.还要添加宏Q_OBJECT
在继承时需要注意,祖父类必须放在父类之前。
一切准备就绪,再次编译总是出现
Class CalendarItem implements the interface QGraphicsItem but does
not list it in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!
这个警告虽然不是错误,但是让我看着很不爽。于是就上网搜索此类答案,
在我的异常网上搜得结果是没有实现下列接口:
但是当我实现后编译还有错。于是就打开QT帮助文档,展现在我面前的令我眼前一亮。
于是我终于思得结果。好高兴啊。
以上是小弟的见解,不对之处多多指出,我们一起进步,一起努力。
添加的过程中遇到了许多问题,现总结如下:
1.要自定义添加信号槽必须要继承QObject。
2.还要添加宏Q_OBJECT
在继承时需要注意,祖父类必须放在父类之前。
一切准备就绪,再次编译总是出现
Class CalendarItem implements the interface QGraphicsItem but does
not list it in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!
这个警告虽然不是错误,但是让我看着很不爽。于是就上网搜索此类答案,
在我的异常网上搜得结果是没有实现下列接口:
void keyPressEvent(QKeyEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
但是当我实现后编译还有错。于是就打开QT帮助文档,展现在我面前的令我眼前一亮。
class BasicToolsPlugin : public QObject, public BrushInterface, public ShapeInterface, public FilterInterface { Q_OBJECT Q_INTERFACES(BrushInterface ShapeInterface FilterInterface) public: ... };
于是我终于思得结果。好高兴啊。
以上是小弟的见解,不对之处多多指出,我们一起进步,一起努力。
相关文章推荐
- QT 编译警告 qobject_cast to QGraphicsItem will not work
- Qt 编译出错 Could not create directory
- 错误 You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work
- linux下编译QT出错:QMAKESPEC has not been set, so configuration cannot be deduced
- TF42097: A work item could not be created due to a field error
- qt+mingw编译出错,提示undefined reference to `**@**'
- QWebView在 Qt 5.x中编译出错:File not found: main.obj
- What components are not suitable to work as component interfaces
- ADS编译出错“Error : (Fatal) L6015U: Could not find any input files to link.”
- QWebView在 Qt 5.x中编译出错:File not found: main.obj
- 解决mac下qt工程编译错误:Xcode not set up properly. You may need to confirm the license agreement by running
- 'You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work.'<>
- QT编译出错解决 libQtCore.so: undefined reference to `QInotifyFileSystemWatcherEngine::create()'
- android混淆编译出错java.lang.Class cannot be cast to java.lang.reflect....
- Office:Spell Checking will not work when upgraded from 2003 to 2010
- You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work.
- imx6编译出错“WARNING: Failed to fetch URL http:// code.qt.io.qt.qt3d.git ”
- Maven-010-maven 编译报错:Failure to ... in ... was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced.
- Effective Java 英文 第二版 读书笔记 Item 4:Attempting to enforce noninstantiability by making a class abstract does not work.
- Qt for Android编译报错提示:Install to device:No Buildfile:build.xml does not exist!解决方法