Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt moc_uuu包含文件问题_C++_Qt_Qt4 - Fatal编程技术网

C++ Qt moc_uuu包含文件问题

C++ Qt moc_uuu包含文件问题,c++,qt,qt4,C++,Qt,Qt4,我试图在编译基础教程程序时遇到了一个问题 按照教程程序的方式进行操作会产生编译错误: In file included from debug\moc_mainwindow.cpp:10: debug\../mainwindow.h:2: error: expected class-name before '{' token debug\../mainwindow.h:5: error: ISO C++ forbids declaration of `Q_OBJECT' with no type

我试图在编译基础教程程序时遇到了一个问题

按照教程程序的方式进行操作会产生编译错误:

In file included from debug\moc_mainwindow.cpp:10:
debug\../mainwindow.h:2: error: expected class-name before '{' token
debug\../mainwindow.h:5: error: ISO C++ forbids declaration of `Q_OBJECT' with no type
问题是需要

#include <QtGui>
教程程序将其放在mainwindow.cpp中,这是实现此功能的理想方法,但不会将其复制到moc文件中

如果我把它放在mainwindow.h中,一切都正常,但是在每个头文件中这样做是不雅观的,一旦程序变大,编译时间就会延长


这是自编写教程以来发生的变化吗?我正在使用最新的Qt4.5.3,WindowsSDK安装,从命令行编译。我遗漏了什么,或者这个问题有任何已知的修复方法吗?

您的头文件必须知道Qt的内容。因此,没有办法避免包含QtGui

编辑:您不应该太担心编译时间。不管怎样,夹杂都会发生。如果标题真的很烦人,也许你可以将标题拆分为与Qt无关的部分。

在标题中包含include就足够了。这是必需的,因为QMainWindow是mainwindow.h中声明的类的基类


当然,除了简单的示例/测试程序外,即使在cpp文件中使用所有内容和厨房水槽标题也不是一个好主意,因为它们会不必要地降低编译速度。

有时我发现moc文件过时,或者更可能的是,首先不会生成。通常通过项目的全面清理和重建来修复


在使用QtCreator时,这种情况主要发生在我最初没有放置Q_对象宏,但后来添加了它的时候。qmake步骤似乎没有重新检查是否必须通过moc传递文件。

公平地说,我可以接受它。谢谢