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 ?
You can try copying all the .dll that you find in C:\\Qt\\5.5\\mingw492_32\\bin into your executable folder (you can see it befor -1073741515 (0xC0000135): is something like C:\\Users{yourName}.CLion2016.2\\system\\cmake\\generated{nameproject}-34b1f222\\34b1f222\\Debug Then run your project from Clion. If it shows you a window you can select the dlls that you have copied and (while the exe is running) try to delete them: the system will hold only ones it needs. I did so when I used QT for the first time. Then i changed my CMake and now it works without dlls in the executable folder. I use MinGw downloaded from here
cmake_minimum_required(VERSION 3.3)
project(Timer_Scandiffio)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp MyClock.cpp MyClock.h
TimerDisplay.cpp TimerDisplay.h MyTimerApp.h
MyTimerApp.cpp MyTimerApp.ui )
add_executable(Timer_Scandiffio ${SOURCE_FILES})
set(QT5 NEED)
find_package( Qt5Core REQUIRED)
find_package( Qt5Gui REQUIRED)
find_package( Qt5Widgets REQUIRED)
find_package( Qt5Multimedia REQUIRED)
target_link_libraries(Timer_Scandiffio Qt5::Core)
target_link_libraries(Timer_Scandiffio Qt5::Gui)
target_link_libraries(Timer_Scandiffio Qt5::Widgets)
target_link_libraries(Timer_Scandiffio Qt5::Multimedia)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.