Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Debug and executing QT project with cmake and CLion
QtWS25 Last Chance

Debug and executing QT project with cmake and CLion

Scheduled Pinned Locked Moved Unsolved General and Desktop
cmakeclion-ideqt 5.5
6 Posts 6 Posters 10.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Artur66A Offline
    Artur66A Offline
    Artur66
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SaundersB
        wrote on last edited by
        #3

        I just wanted to say thank you for posting this. It helped me in integrating Qt with CLion using MinGW-32.

        D 1 Reply Last reply
        1
        • E Offline
          E Offline
          eti_nne
          wrote on last edited by
          #4

          Hi,

          Regarding the debug symbols, you might just need to set the cmake var CMAKE_BUILD_TYPE to Debug.
          I'm pretty sure that you already have qt debug since they are included in the standard install.

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ismailsunni
            wrote on last edited by
            #5

            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 ?
            
            1 Reply Last reply
            0
            • S SaundersB

              I just wanted to say thank you for posting this. It helped me in integrating Qt with CLion using MinGW-32.

              D Offline
              D Offline
              Dariusz
              wrote on last edited by Dariusz
              #6

              @SaundersB Would you be able yo share the sample code as to how you managed to solve this issue? I tried for 2 days now and the only working solution I found was to copy the QT dlls to my project.

              Regards
              Dariusz

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved