相关疑难解决方法(0)

Qt 5 cmake失败,未知定义引用hello world上的vtable,inc&src为子目录

更新2

稍微搞砸了(以及对生成的Makefile的一些编辑),看起来正在发生的是moc没有正确处理MainWindow.h(包括在内main.cpp,MainWindow.cpp除非它与包含它的源文件位于同一文件夹中).

Moc运行MainWindow.cpp,不处理包含,因此没有看到Q_OBJECT宏,因此继续产生一个空的输出文件.我不确定moc通常是进程包含还是只是扫描目录,但无论哪种方式,需要mocing但在其他目录中的头文件都没有被处理!

更新

问题似乎与moc产生的输出有关.在第一种情况下(编译的那个),hello-world_automoc.cppmoc_MainWindow.cpp生成.hello-world_automoc.cpp好像

/* This file is autogenerated, do not edit*/
#include "moc_MainWindow.cpp"
Run Code Online (Sandbox Code Playgroud)

在第二种情况下,hello-world_automoc.cpp产生了一个看起来像的

/* This file is autogenerated, do not edit*/
enum some_compilers { need_more_than_nothing };
Run Code Online (Sandbox Code Playgroud)

并且根本没有moc_MainWindow.cpp.如果我从cmake手动调用moc而不是在破碎的情况下使用automoc,我确实得到moc_MainWindow.cpp但它是空的.

原始状态

首先,不,我没有忘记set(CMAKE_AUTOMOC ON).还要注意的是MainWindow析构函数声明和实现.

当我的目录结构如下所示:

CMakeLists.txt
|__ main.cpp
|__ MainWindow.cpp
|__ MainWindow.h
|__ MainWindow.ui

编译工作得很好.

但是,当它看起来像:

helloworld/
|__ CMakeLists.txt
|__ src/
|   |__ CMakeLists.txt
| …

c++ linker qt cmake moc

12
推荐指数
2
解决办法
1万
查看次数

找不到 ui 头文件 (ui_name.h)

我创建了表单,将其保存在项目目录中。现在我想添加一些代码。所以,我创建了头文件:

#ifndef SORTDIALOG_H
#define SORTDIALOG_H

#include <QtWidgets/QDialog>
#include <QtWidgets/QWidget>


#include "ui_sortdialog.h"


class SortDialog: public QDialog, public Ui::SortDialog
{
    Q_OBJECT
public:
    SortDialog(QWidget *parent=0);
    void setColumnRange(QChar first, QChar last);
}

#endif // SORTDIALOG_H
Run Code Online (Sandbox Code Playgroud)

在编写代码 Qt creator 看到 ui_sortdialog.h,例如,我可以看到“Ui”命名空间。但是当我试图编译器写到 ui_sortdialog.h 没有找到

C:\Qt\Qt5.1.1\Tools\QtCreator\bin\untitled2\sortdialog.h:8: error: ui_sortdialog.h: No such file or directory
 #include "ui_sortdialog.h"
                       ^
Run Code Online (Sandbox Code Playgroud)

c++ qt

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×2

qt ×2

cmake ×1

linker ×1

moc ×1