Debug and executing QT project with cmake and CLion
-
I try run QT project with cmake and CLion. On my Windows 10 I have installed MinGw and QT. I got folder source with this 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 very common, the same that in start project in QT creator. Now I have my CmakeList 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 fetch cmakelist without errors and warning. Next compilation going also without errors. When I finally run program window not show up. I see only that app return this code: -1073741515 (0xC0000135). Why QT didnt open window ? Second thing, when I set in CLion in some place breakpoint and I run debug mode CLion didnt stop in my brakepoint, this looks like current lib didnt have debug symbols, how to easiest add debug version of qt library ?
-
Hi and welcome to devnet,
You also need to setup the run environment in order for your application to start. i.e. Qt Creator modifies the PATH environment variable and adds the current used Qt's bin folder to PATH.
Hope it helps
-
How did you solve this problem?:
Second thing, when I set in CLion in some place breakpoint and I run debug mode CLion didnt stop in my brakepoint, this looks like current lib didnt have debug symbols, how to easiest add debug version of qt library ?