点击打开链接

#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'

最早接触到这类设计其实是从Borland C++ Builder 开始的,作为一个所谓的快速开发工具,其实我对其实现界面设计那块到现在都没有清晰的理解。后来接触了Java 一段时间,那时候只懂得自己设计界面就是继承一个类,如主窗口或者 applet,然后在该类中添加很多其他的 component 作为其 protected 成员。可是很少考虑到怎么更方便的设计。因此,可以说接触到第一个这种设计思想的GUI 库就是在 Qt 了。 不得不说 Qt 其实和 Java 很像,虽然说 Qt 是 C++ 写成,但是注意到它其实是单一祖先 QObject 一脉相承,通过 QMetaObject 实现的RTTI,这多多少少和Java单一祖先一致,但是 Qt 不排斥使用其他的 C++ class,只是失去了 signal/slot 机制。在 moc 的 man page 里面,其实介绍了 Qt 实现的种种局限性:

我们无法使用 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' 错误相关推荐

  1. error: 'staticMetaObject' is not a member of 'QGraphicsItem'

    error: 'staticMetaObject' is not a member of 'QGraphicsItem' 在类定义的时候,增加下面的描述: class MyItem:public QO ...

  2. 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 ...

  3. 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 ...

  4. 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 文章性质:原创文章 今天帮主在群里看到有一个兄弟在 ...

  5. 安装Python2.7出现configure: error: no acceptable C compiler found in $PATH错误

    安装Python2.7出现configure: error: no acceptable C compiler found in $PATH错误 安装步骤: 安装依赖 yum groupinstall ...

  6. caffe中在某一层获得迭代次数的方法以及caffe编译时报错 error: ‘to_string‘ is not a member of ‘std‘解决方法

    caffe中在某一层获得迭代次数的方法以及caffe编译时报错 error: 'to_string' is not a member of 'std'解决方法 参考文章: (1)caffe中在某一层获 ...

  7. c++中调用python脚本提示 error LNK2001: 无法解析的外部符号 __imp_Py_Initialize等错误的解决方法

    c++中调用python脚本提示 error LNK2001: 无法解析的外部符号 __imp_Py_Initialize等错误的解决方法 时间:2017-05-09 12:32:06阅读:234评论 ...

  8. error: ‘to_string’ is not a member of ‘std’———已解决

    现象¶ cocos2d-x 2.2.6 项目的源码中使用了 std::to_string() 方法,使用 NDK r9d 编译的时候,报如下错误: error: 'to_string' is not ...

  9. error while loading shared libraries:libmysqlclient.so.18 错误

    error while loading shared libraries:libmysqlclient.so.18错误 新手安装php的时候如果出现这种问题,解决办法很简单,就是查看你的mysql安装 ...

最新文章

  1. 【HM】第5课:JDBC连接MySQL数据库
  2. LiveVideoStackCon 2019北京你来吗?
  3. 苹果正为iPhone 12开发磁性电池组 可为手机无线充电
  4. mysqlin索引失效的情况
  5. 轮播图的效果实现小米商城和京东商城
  6. paip.java 开发中web server的选择jboss resin tomcat比较..
  7. 蒜头君的生日(日期格式)
  8. wincc中c语言做变量自增,在WinCC中如何利用C动作实现变量自动加1-工业支持中心-西门子中国...
  9. 数据库基础知识和SQL语言
  10. Informatic学习总结_day02_增量抽取
  11. 百度地图---之---行政区域划分
  12. Code For Better 谷歌开发者之声——Flutter - Google 开源的移动 UI 框架
  13. win10磁盘管理_Win10磁盘管理器:轻松和安全地调整Win10的分区大小
  14. centos7安装有道词典
  15. 计算机视觉书籍资源推荐_Computer Vision Principles, Algorithms, Applications, Learning
  16. 《新参者-加贺恭一郎》、《麦田里的守望者》杂记
  17. Android解析包时出现问题
  18. hbase —— Dead Region Servers
  19. Unity3D获取当前键盘按键及Unity3D鼠标、键盘的基本操作
  20. 8421码5421码2421码余3码

热门文章

  1. ASP.NET设置数据格式与String.Format使用总结
  2. 转换字符串中汉字为其拼音缩写(C#)
  3. SQL Server 中各个系统表的作用
  4. 正则表达式--检查颜色值
  5. 使用VC实现一个“智能”自增减线程池
  6. Ruby Metaprogramming
  7. 山东大学计算机学院预推免,山东大学计算机科学与技术学院(专业学位)计算机技术保研...
  8. iphone清理缓存小技巧_苹果手机清理垃圾小技巧!小内存也不发愁
  9. 加载vue文件步骤_无法在重新加载时读取vue文件
  10. npm包开发测试与发布