【发布时间】:2016-06-19 07:00:07
【问题描述】:
我尝试使用 cmake 和 CLion 运行 QT 项目。在我的 Windows 10 上,我安装了 MinGw 和 QT。我得到了这个文件的文件夹源:
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
主窗口.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
主窗口.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
和 mainwindow.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>435</width>
<height>308</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>124</x>
<y>100</y>
<width>151</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>My Button :)</string>
</property>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
我的代码结构很普通,和QT creator中的启动项目一样。现在我有了我的 CmakeList 文件:
cmake_minimum_required(VERSION 3.3)
project(MyProject)
set (CMAKE_PREFIX_PATH "C:\\Qt\\5.5\\mingw492_32")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Qt5Widgets)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_library(mainwindow sources/mainwindow.cpp)
target_link_libraries (mainwindow Qt5::Widgets)
add_executable(qtProject sources/main.cpp)
target_link_libraries(qtProject Qt5::Widgets mainwindow)
Cmake 获取 cmakelist 没有错误和警告。下一次编译也没有错误。当我最终运行程序窗口时没有出现。我只看到该应用程序返回此代码:-1073741515 (0xC0000135)。为什么QT没有打开窗口?第二件事,当我在 CLion 的某个地方设置断点并运行调试模式时,CLion 没有在我的刹车点停止,这看起来像当前库没有调试符号,如何最简单地添加 qt 库的调试版本?
【问题讨论】: