zoukankan      html  css  js  c++  java
  • 关于添加Q_OBJECT后引发的错误

    关于添加Q_OBJECT后引发的错误

    Q_OBJECT 

    :The Q_OBJECT macro at the beginning of the class definition is necessary for all classes that define signals or slots.

    在QGIS中,对于那些在类中需要添加 信号槽的类,就需要在该类定义的时候的添加 Q_OBJECT这个宏命令,这个是必须的

    To compile the program, run qmake as usual. Since the FindDialog class definition contains the Q_OBJECT macro, the makefile generated by qmake will include special rules to run moc, Qt's meta-object compiler. (We cover Qt's meta-object system in the next section.)

    For moc to work correctly, we must put the class definition in a header file, separate from the implementation file. The code generated by moc includes this header file and adds some C++ boilerplate code of its own.

    Classes that use the Q_OBJECT macro must have moc run on them. This isn't a problem because qmake automatically adds the necessary rules to the makefile. But if you forget to regenerate your makefile using qmake and moc isn't run, the linker will complain that some functions are declared but not implemented. The messages can be fairly obscure. GCC produces error messages like this one:

    finddialog.o: In function `FindDialog::tr(char const*, char const*)':
    /usr/lib/qt/src/corelib/global/qglobal.h:1430: undefined reference to
    `FindDialog::staticMetaObject'

    Visual C++'s output starts like this:

    finddialog.obj : error LNK2001: unresolved external symbol
    "public:~virtual int __thiscall MyClass::qt_metacall(enum QMetaObject
    ::Call,int,void * *)"

    If this ever happens to you, run qmake again to update the makefile, then rebuild the application.

     

    我使用的VS 2008,但是在实际的操作过程中,尽管我按照上面的命令重新编译了上面的文件,单是仍然会报错,经过反复测试,我发现,添加一个带有Q_OBJECT的类后,在执行上述命令后,需要将vs的解决方案文件删除掉,然后在运行上面的命令,重新生成.sln解决方案,然后重新打开工程,这个问题就解决了,虽然这个方法比较笨蛋,有点麻烦,但在好的方法发现之前,这仍是一个解决问题的方法。

     

    THE END!

    2012年12月28日

  • 相关阅读:
    Log4J输出日志到WEB工程目录的实现方法
    MyEclipse 10 中增加svn插件
    Web 项目添加log4j
    ruby on rails 之旅 第一章 ubuntu11.10安装
    ruby on rails 之旅 第一章 ubuntu12.04安装
    centos 6.3 server 安装mysql5
    技术实践第四期|解读移动开发者日常性能监控平台应用
    电脑一族预防颈椎劳损八法
    方便的使用单击和双击更新DataGrid中的数据的例子(转载)
    不重复随机数列生成算法
  • 原文地址:https://www.cnblogs.com/xingchen/p/2836843.html
Copyright © 2011-2022 走看看