2

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?

1 Answer 1

0

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) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.