I try to run a Qt project with CMake and CLion. On Windows 10, I have installed MinGW and Qt. I have a source folder with these files:
main.cpp
#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } mainwindow.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; } mainwindow.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 and 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> My code structure is the same as in the start project in Qt Creator. Now I have a CMakeLists.txt file:
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 configures without errors and warning. Next compilation also succeeds without errors. When I finally run program, the window does not show up. The app only returns this code: -1073741515 (0xC0000135). Why didn't Qt open a window? Second thing, when I set a breakpoint somewhere in CLion and I run debug mode, it doesn't stop in my breakpoint. It looks as if the library didn't have debug symbols. How can I add the debug version of Qt libraries?