Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Build and Run from Command Line
Forum Update on Tuesday, May 27th 2025

Build and Run from Command Line

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
13 Posts 6 Posters 3.0k Views 5 Watching
  • 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.
  • S Offline
    S Offline
    Sebastiano Zamberlan
    wrote on 12 Jan 2024, 11:16 last edited by
    #1

    What is the correct way to launch from 0 the build and then run of a Qt6 project (Cmake) via command line.

    Take for example a QtQuick Application project

    How can i from Powershell build and then run the project?

    S 1 Reply Last reply 12 Jan 2024, 11:41
    1
    • S Sebastiano Zamberlan
      12 Jan 2024, 11:16

      What is the correct way to launch from 0 the build and then run of a Qt6 project (Cmake) via command line.

      Take for example a QtQuick Application project

      How can i from Powershell build and then run the project?

      S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 12 Jan 2024, 11:41 last edited by
      #2

      @Sebastiano-Zamberlan the process is similar to any other cmake project:

      cmake -S /path/to/source-code -B . 
      cmake --build . --parallel --config Release
      

      Then you either run the executable right away or perhaps run deployment first (windeployqt).

      (Z(:^

      S 1 Reply Last reply 12 Jan 2024, 13:13
      2
      • S sierdzio
        12 Jan 2024, 11:41

        @Sebastiano-Zamberlan the process is similar to any other cmake project:

        cmake -S /path/to/source-code -B . 
        cmake --build . --parallel --config Release
        

        Then you either run the executable right away or perhaps run deployment first (windeployqt).

        S Offline
        S Offline
        Sebastiano Zamberlan
        wrote on 12 Jan 2024, 13:13 last edited by
        #3

        @sierdzio How can I specify that I want it to be compiled with mingw_64

        C P 2 Replies Last reply 12 Jan 2024, 13:35
        0
        • S Sebastiano Zamberlan
          12 Jan 2024, 13:13

          @sierdzio How can I specify that I want it to be compiled with mingw_64

          C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 12 Jan 2024, 13:35 last edited by
          #4

          @Sebastiano-Zamberlan said in Build and Run from Command Line:

          How can I specify that I want it to be compiled with mingw_64

          What does this mean? You create a CMakeLists.txt like it's done in QtCreator or any other ide which cmake then processes.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          S 1 Reply Last reply 12 Jan 2024, 14:19
          0
          • C Christian Ehrlicher
            12 Jan 2024, 13:35

            @Sebastiano-Zamberlan said in Build and Run from Command Line:

            How can I specify that I want it to be compiled with mingw_64

            What does this mean? You create a CMakeLists.txt like it's done in QtCreator or any other ide which cmake then processes.

            S Offline
            S Offline
            Sebastiano Zamberlan
            wrote on 12 Jan 2024, 14:19 last edited by
            #5

            @Christian-Ehrlicher, @sierdzio let's take an example, I create a new project ( in this case QtQuick Application )
            I leave the code as is and try from terminal to run

            cmake -S /path/to/source-code -B .
            

            this is what appears to me.

            -- Building for: Visual Studio 15 2017
            -- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19045.
            -- The CXX compiler identification is MSVC 19.16.27051.0
            -- Detecting CXX compiler ABI info
            -- Detecting CXX compiler ABI info - done
            -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped
            -- Detecting CXX compile features
            -- Detecting CXX compile features - done
            CMake Error at CMakeLists.txt:8 (find_package):
              By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
              asked CMake to find a package configuration file provided by "Qt6", but
              CMake did not find one.
            
              Could not find a package configuration file provided by "Qt6" (requested
              version 6.2) with any of the following names:
            
                Qt6Config.cmake
                qt6-config.cmake
            
              Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
              to a directory containing one of the above files.  If "Qt6" provides a
              separate development package or SDK, be sure it has been installed.
            
            
            -- Configuring incomplete, errors occurred!
            

            I wanted to know meanwhile how to specify my intention to use mingw_64 as compiler

            C 1 Reply Last reply 12 Jan 2024, 14:40
            1
            • S Sebastiano Zamberlan
              12 Jan 2024, 14:19

              @Christian-Ehrlicher, @sierdzio let's take an example, I create a new project ( in this case QtQuick Application )
              I leave the code as is and try from terminal to run

              cmake -S /path/to/source-code -B .
              

              this is what appears to me.

              -- Building for: Visual Studio 15 2017
              -- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19045.
              -- The CXX compiler identification is MSVC 19.16.27051.0
              -- Detecting CXX compiler ABI info
              -- Detecting CXX compiler ABI info - done
              -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped
              -- Detecting CXX compile features
              -- Detecting CXX compile features - done
              CMake Error at CMakeLists.txt:8 (find_package):
                By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
                asked CMake to find a package configuration file provided by "Qt6", but
                CMake did not find one.
              
                Could not find a package configuration file provided by "Qt6" (requested
                version 6.2) with any of the following names:
              
                  Qt6Config.cmake
                  qt6-config.cmake
              
                Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
                to a directory containing one of the above files.  If "Qt6" provides a
                separate development package or SDK, be sure it has been installed.
              
              
              -- Configuring incomplete, errors occurred!
              

              I wanted to know meanwhile how to specify my intention to use mingw_64 as compiler

              C Online
              C Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 12 Jan 2024, 14:40 last edited by
              #6

              You have to set up your env correctly before by starting the command line through the 'Qt 6.x.x (MinGW64) menu entry. Then the PATH is correctly set up and the mingw compiler is found & used. Start over with a clean build dir.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              S 1 Reply Last reply 12 Jan 2024, 15:45
              2
              • C Christian Ehrlicher
                12 Jan 2024, 14:40

                You have to set up your env correctly before by starting the command line through the 'Qt 6.x.x (MinGW64) menu entry. Then the PATH is correctly set up and the mingw compiler is found & used. Start over with a clean build dir.

                S Offline
                S Offline
                Sebastiano Zamberlan
                wrote on 12 Jan 2024, 15:45 last edited by Sebastiano Zamberlan 1 Dec 2024, 16:17
                #7

                @Christian-Ehrlicher @sierdzio

                I tried but still the same error,
                I also ran the command

                --system-information information.txt 
                

                and in the .txt the path goes to the Visual Studio

                In fact the message that cmake sent me was always:

                -- Building for: Visual Studio 15 2017
                
                C 1 Reply Last reply 12 Jan 2024, 16:23
                1
                • S Sebastiano Zamberlan
                  12 Jan 2024, 15:45

                  @Christian-Ehrlicher @sierdzio

                  I tried but still the same error,
                  I also ran the command

                  --system-information information.txt 
                  

                  and in the .txt the path goes to the Visual Studio

                  In fact the message that cmake sent me was always:

                  -- Building for: Visual Studio 15 2017
                  
                  C Online
                  C Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 12 Jan 2024, 16:23 last edited by
                  #8

                  @Sebastiano-Zamberlan Then pass -DCMAKE_CXX_COMPILER=g++ and make sure g++ --version print something useful (which should when you set up the env correct).

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  2
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 12 Jan 2024, 20:01 last edited by
                    #9

                    Hi,

                    In addition to @Christian-Ehrlicher, the Qt 6 versions you installed have a qt-cmake script that are tuned for the installation they are in.

                    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
                    1
                    • S Sebastiano Zamberlan
                      12 Jan 2024, 13:13

                      @sierdzio How can I specify that I want it to be compiled with mingw_64

                      P Offline
                      P Offline
                      Paul Colby
                      wrote on 12 Jan 2024, 21:10 last edited by
                      #10

                      @Sebastiano-Zamberlan said in Build and Run from Command Line:

                      @sierdzio How can I specify that I want it to be compiled with mingw_64

                      The easiest way, I think, is to use CMake's MinGW Makefiles generator, like:

                      cmake -G "MinGW Makefiles" ...
                      

                      As @SGaist wrote, if you're using Qt 6, then you can use Qt's qt-cmake wrapper, so:

                      X:\path\to\qt\installation\qt-cmake.bat -G "MinGW Makefiles" -S <src-dir> -B <build-dir>
                      

                      All qt-cmake does (today) is set CMake's CMAKE_TOOLCHAIN_FILE variable, so it's equivalent to:

                      cmake.exe -DCMAKE_TOOLCHAIN_FILE="X:\path\to\qt\installation\lib\cmake\qt.toolchain.cmake" -G "MinGW Makefiles" -S <src-dir> -B <build-dir>
                      

                      Cheers.

                      S 1 Reply Last reply 18 Jan 2024, 10:36
                      4
                      • P Paul Colby
                        12 Jan 2024, 21:10

                        @Sebastiano-Zamberlan said in Build and Run from Command Line:

                        @sierdzio How can I specify that I want it to be compiled with mingw_64

                        The easiest way, I think, is to use CMake's MinGW Makefiles generator, like:

                        cmake -G "MinGW Makefiles" ...
                        

                        As @SGaist wrote, if you're using Qt 6, then you can use Qt's qt-cmake wrapper, so:

                        X:\path\to\qt\installation\qt-cmake.bat -G "MinGW Makefiles" -S <src-dir> -B <build-dir>
                        

                        All qt-cmake does (today) is set CMake's CMAKE_TOOLCHAIN_FILE variable, so it's equivalent to:

                        cmake.exe -DCMAKE_TOOLCHAIN_FILE="X:\path\to\qt\installation\lib\cmake\qt.toolchain.cmake" -G "MinGW Makefiles" -S <src-dir> -B <build-dir>
                        

                        Cheers.

                        S Offline
                        S Offline
                        Sebastiano Zamberlan
                        wrote on 18 Jan 2024, 10:36 last edited by
                        #11

                        @Paul-Colby @Christian-Ehrlicher @SGaist @sierdzio

                        Thank you guys, this information is very helpful,

                        I was able to launch from the specific terminal, now I want to understand what the "qtenv2.bat" contains and how it acts so that I can make a .bat or a general .py that allows me to launch a build.

                        jsulmJ 1 Reply Last reply 18 Jan 2024, 10:47
                        0
                        • S Sebastiano Zamberlan
                          18 Jan 2024, 10:36

                          @Paul-Colby @Christian-Ehrlicher @SGaist @sierdzio

                          Thank you guys, this information is very helpful,

                          I was able to launch from the specific terminal, now I want to understand what the "qtenv2.bat" contains and how it acts so that I can make a .bat or a general .py that allows me to launch a build.

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 18 Jan 2024, 10:47 last edited by
                          #12

                          @Sebastiano-Zamberlan said in Build and Run from Command Line:

                          I want to understand what the "qtenv2.bat" contains and how it acts

                          Open it in a text editor

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          S 1 Reply Last reply 18 Jan 2024, 11:40
                          2
                          • jsulmJ jsulm
                            18 Jan 2024, 10:47

                            @Sebastiano-Zamberlan said in Build and Run from Command Line:

                            I want to understand what the "qtenv2.bat" contains and how it acts

                            Open it in a text editor

                            S Offline
                            S Offline
                            Sebastiano Zamberlan
                            wrote on 18 Jan 2024, 11:40 last edited by
                            #13

                            @jsulm yeah 👍

                            1 Reply Last reply
                            0
                            • S Sebastiano Zamberlan has marked this topic as solved on 19 Jan 2024, 10:19

                            1/13

                            12 Jan 2024, 11:16

                            • Login

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