继承QTreeWidgetItem发生error: 'staticMetaObject' is not a member of 'QTreeWidgetItem' 错误
点击打开链接
#ifndef QQUSERITEM_H就发生下列错误
#define QQUSERITEM_H
#include <QTreeWidgetItem>
class QQUserItem :public QTreeWidgetItem
{
Q_OBJECT
public:
explicit QQUserItem(QQUserItem *parent = 0);
signals:
public slots:
};
#endif // QQUSERITEM_H
debug\moc_QQUserItem.cpp:41:8: error: 'staticMetaObject' is not a member of 'QTreeWidgetItem'
..\..\Qt\4.6.3\include/QtCore/../../src/corelib/kernel/qobject.h: In member function 'virtual const QMetaObject* QQUserItem::metaObject() const':
..\..\Qt\4.6.3\include/QtCore/../../src/corelib/kernel/qobject.h:296:33: error: 'QScopedPointer<QObjectData> QObject::d_ptr' is protected
debug\moc_QQUserItem.cpp:51:21: error: within this context
..\..\Qt\4.6.3\include/QtCore/../../src/corelib/kernel/qobject.h:296:33: error: object missing in reference to 'QObject::d_ptr'
debug\moc_QQUserItem.cpp:51:21: error: from this location
..\..\Qt\4.6.3\include/QtCore/../../src/corelib/kernel/qobject.h:296:33: error: 'QScopedPointer<QObjectData> QObject::d_ptr' is protected
debug\moc_QQUserItem.cpp:51:50: error: within this context
..\..\Qt\4.6.3\include/QtCore/../../src/corelib/kernel/qobject.h:296:33: error: object missing in reference to 'QObject::d_ptr'
debug\moc_QQUserItem.cpp:51:50: error: from this location
debug\moc_QQUserItem.cpp: In member function 'virtual void* QQUserItem::qt_metacast(const char*)':
debug\moc_QQUserItem.cpp:59:12: error: 'qt_metacast' is not a member of 'QTreeWidgetItem'
debug\moc_QQUserItem.cpp: In member function 'virtual int QQUserItem::qt_metacall(QMetaObject::Call, int, void**)':
debug\moc_QQUserItem.cpp:64:11: error: 'qt_metacall' is not a member of 'QTreeWidgetItem'
debug\moc_QQUserItem.cpp: In member function 'virtual void* QQUserItem::qt_metacast(const char*)':
debug\moc_QQUserItem.cpp:60:1: warning: control reaches end of non-void function
debug\moc_QQUserItem.cpp: In member function 'virtual const QMetaObject* QQUserItem::metaObject() const':
debug\moc_QQUserItem.cpp:52:1: warning: control reaches end of non-void function
mingw32-make[1]: *** [debug/moc_QQUserItem.o] Error 1
mingw32-make: *** [debug] Error 2
The process "D:/MinGW/bin/mingw32-make.exe" exited with code %2.
Error while building project MyQQ (target: Desktop)
When executing build step 'Make'
修改成这样 class QQUserItem :public QObject,public QTreeWidgetItem就没错误了,搜到了如下资料:
居然有这样的错误:'staticMetaObject' is not a member of 'Ui::MainWindow'
我们无法使用 template 继承 QObject,换言之,下面代码无法被 moc 转换成为有效的 C++ compiler 可编译代码:
template<class>
class TemplateClass : public QObject {
Q_OBJECT
// ...
public slots:
// ...
} ;class>
使用 multiple inheritance 必须把 QObject 或者其子类放在第一个父类的位置(因为使用 Q_OBJECT 需要覆盖),然后继承别的类。颠倒后,如 g++ 会抱错,如
multiclass.hpp:17: Warning: Class MultiClass inherits from two QObject subclasses NoneQtClass and QObject. This is not supported!
moc_multiclass.cpp:39: error: ‘staticMetaObject’ is not a member of ‘NoneQtClass’
moc_multiclass.cpp: In member function ‘virtual void* MultiClass::qt_metacast(const char*)’:
moc_multiclass.cpp:55: error: ‘qt_metacast’ is not a member of ‘NoneQtClass’
moc_multiclass.cpp: In member function ‘virtual int MultiClass::qt_metacall(QMetaObject::Call, int, void**)’:
moc_multiclass.cpp:60: error: ‘qt_metacall’ is not a member of ‘NoneQtClass’
make: *** [moc_multiclass.o] Error 1 MultiClass 继承 QObject 和 NoneQtClass,插入的 Q_OBJECT 展开后,因为将 NoneQtClass 放在第一位后 MultiClass 的结构已经不是 QObject 在前面所以创建staticMetaObject 出错,后面虚函数表也因为在后面所以导致使用的其实是前面那个 class 的 vtable。
函数指针不能作为 signal/slot 的参数,这个可以用 typedef 克服,如
class SomeClass : public QObject
{
Q_OBJECT
//...
public slots:
// illegal
void apply( void (*apply)(List *, void *), void * );
}; 将被认为非法(主要是判断参数类型时会失败,记得 QMetaObject 存下来的是什么信息么?),但是
typedef void (*ApplyFunctionType)( List *, void * );
class SomeClass : public QObject
{
Q_OBJECT
//...
public slots:
void apply( ApplyFunctionType, char * );
}; 是可行的。
友 元声明最好不要放在 signal 和 slot 声明中,这很明显,因为多数情况下虽然根据宏替换, signals: 被替换为 protected:,slots 被替换为空,但是编译器处理 friend 可能并不完全这样无关的处理,理论上说标准的编译器应该能 work,如 g++ 4.3.3.
signal 和 slot 不能被 upgrade,这是因为 moc 需要一个完整的函数声明,而提升的时候声明是不完整的,如
class SlotClass : public QObject
{
Q_OBJECT
protected slots:
int getValue() ;
} ;
class UpgradeSlotClass : public SlotClass
{
Q_OBJECT
public slots:
Slot::getValue ;
} ; 其中的 Slot::getValue 的提升在正常的情况是被允许的,可见报错的是 moc,
/usr/bin/moc-qt4 -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. upgradeslotclass.hpp -o moc_upgradeslotclass.cpp
upgradeslotclass.hpp:15: Error: Not a signal or slot declarationsignal 和 slot 的参数不能使用宏,这是因为 moc 不展开宏。
嵌套类声明不应该出现在 signal 或者 slot 里面,也是因为 moc 不能处理的原因。
构造函数不应出现在 signal 和 slot 里面,虽然是函数,但是没有必要。
Q_PROPERTY 宏声明属性时应在包含其读写函数的 public 节之前,写在同一个 public 里面不允许,注意
#define Q_PROPERTY(text)其实在类声明时这句话没有任何作用,只是 moc 编译会产生对应的代码,而 moc 要求这部分必须以类似下面的方式书写
class PropertyClass : public QObject
{
Q_OBJECT
Q_PROPERTY( int value READ getValue WRITE setValue )
转载于:https://www.cnblogs.com/Podevor/archive/2011/10/11/2788017.html
继承QTreeWidgetItem发生error: 'staticMetaObject' is not a member of 'QTreeWidgetItem' 错误相关推荐
- error: 'staticMetaObject' is not a member of 'QGraphicsItem'
error: 'staticMetaObject' is not a member of 'QGraphicsItem' 在类定义的时候,增加下面的描述: class MyItem:public QO ...
- python mysql gcc_MySQL-python “error: command 'gcc' failed with exit status 1”错误
安装MySQL-python-1.2.3c1出现"error: command 'gcc' failed with exit status 1"错误 具体报错信息如下: _mysq ...
- g++报错解决:error: ‘setw’ is not a member of ‘std’
下午在用g++编译的时候报错如下: zhang@debian:~/CuteCompiler$ g++ -std=c++11 test.cpp -o test test.cpp: In function ...
- cann't connect to db! mysql!,解决SQL Error: Can't connect to MySQL server on错误
解决SQL Error: Can't connect to MySQL server on错误 文章来源:传奇帮手游 发布时间:2020-12-02 文章性质:原创文章 今天帮主在群里看到有一个兄弟在 ...
- 安装Python2.7出现configure: error: no acceptable C compiler found in $PATH错误
安装Python2.7出现configure: error: no acceptable C compiler found in $PATH错误 安装步骤: 安装依赖 yum groupinstall ...
- caffe中在某一层获得迭代次数的方法以及caffe编译时报错 error: ‘to_string‘ is not a member of ‘std‘解决方法
caffe中在某一层获得迭代次数的方法以及caffe编译时报错 error: 'to_string' is not a member of 'std'解决方法 参考文章: (1)caffe中在某一层获 ...
- c++中调用python脚本提示 error LNK2001: 无法解析的外部符号 __imp_Py_Initialize等错误的解决方法
c++中调用python脚本提示 error LNK2001: 无法解析的外部符号 __imp_Py_Initialize等错误的解决方法 时间:2017-05-09 12:32:06阅读:234评论 ...
- error: ‘to_string’ is not a member of ‘std’———已解决
现象¶ cocos2d-x 2.2.6 项目的源码中使用了 std::to_string() 方法,使用 NDK r9d 编译的时候,报如下错误: error: 'to_string' is not ...
- error while loading shared libraries:libmysqlclient.so.18 错误
error while loading shared libraries:libmysqlclient.so.18错误 新手安装php的时候如果出现这种问题,解决办法很简单,就是查看你的mysql安装 ...
最新文章
- 【HM】第5课:JDBC连接MySQL数据库
- LiveVideoStackCon 2019北京你来吗?
- 苹果正为iPhone 12开发磁性电池组 可为手机无线充电
- mysqlin索引失效的情况
- 轮播图的效果实现小米商城和京东商城
- paip.java 开发中web server的选择jboss resin tomcat比较..
- 蒜头君的生日(日期格式)
- wincc中c语言做变量自增,在WinCC中如何利用C动作实现变量自动加1-工业支持中心-西门子中国...
- 数据库基础知识和SQL语言
- Informatic学习总结_day02_增量抽取
- 百度地图---之---行政区域划分
- Code For Better 谷歌开发者之声——Flutter - Google 开源的移动 UI 框架
- win10磁盘管理_Win10磁盘管理器:轻松和安全地调整Win10的分区大小
- centos7安装有道词典
- 计算机视觉书籍资源推荐_Computer Vision Principles, Algorithms, Applications, Learning
- 《新参者-加贺恭一郎》、《麦田里的守望者》杂记
- Android解析包时出现问题
- hbase —— Dead Region Servers
- Unity3D获取当前键盘按键及Unity3D鼠标、键盘的基本操作
- 8421码5421码2421码余3码
热门文章
- ASP.NET设置数据格式与String.Format使用总结
- 转换字符串中汉字为其拼音缩写(C#)
- SQL Server 中各个系统表的作用
- 正则表达式--检查颜色值
- 使用VC实现一个“智能”自增减线程池
- Ruby Metaprogramming
- 山东大学计算机学院预推免,山东大学计算机科学与技术学院(专业学位)计算机技术保研...
- iphone清理缓存小技巧_苹果手机清理垃圾小技巧!小内存也不发愁
- 加载vue文件步骤_无法在重新加载时读取vue文件
- npm包开发测试与发布