VS2013中添加继承自Qt的类时提示没有moc_xxx.cpp

系统:win7 64

vs2013

qt5.6.0 32

qt add in 1.2.5


新建了一个QMainWindow,在工程中手动添加一个继承自QDialog的类Mydialog。直接添加头文件和实现问题后编译报如下错:

c1xx : fatal error C1083: 无法打开源文件: “GeneratedFilesDebugmoc_MyDialog.cpp”: No such file or directory

错误显示没有moc_MyDialog.cpp,moc开头的文件是Qt自动生成的,这里没有生成所以报错。可以看到在GeneratedFilesDebug目录下是有MainWindow的moc文件的,也就是说用Qt的创建的类,它会生成moc文件,自己手动添加的则不会?那试一下让Qt自己添加试试。

“工程”-“添加”-add Qt Class

类名为MyDialog,Base Class为QDialog, Constructor signature为QWidget *parent,其余默认,finish。再次编译,成功。在GeneratedFilesDebug目录下多了moc_MyDialog.cpp

可见,让Qt自己生成Class不会有编译问题,但我不懂为什么。

原文地址:https://www.cnblogs.com/shanchuan/p/8150312.html