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. No Console Output To Terminal on Windows When Using CMake
Forum Updated to NodeBB v4.3 + New Features

No Console Output To Terminal on Windows When Using CMake

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 4.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.
  • K Offline
    K Offline
    KenAppleby 0
    wrote on 3 Feb 2023, 22:42 last edited by
    #1

    QT6.4 Windows 10:

    I have a console application that runs in a terminal and emits log messages via qDebug(). These messages appear as expected in the terminal when the project is built with qmake but do not appear when the project is built with CMake.

    If the CMake-built executable is run with "Run in terminal" unchecked in the Projects->Run wizard, then qDebug() messages appear correctly in the QtCreator Application Output pane. If the "Run in terminal" is checked, no output appears in either the Application Output pane or the terminal.

    Is there a CMake variable that needs to be set in order to enable terminal output in a CMake console app on Windows?

    Thanks.

    C 1 Reply Last reply 3 Feb 2023, 22:53
    0
    • K KenAppleby 0
      3 Feb 2023, 22:42

      QT6.4 Windows 10:

      I have a console application that runs in a terminal and emits log messages via qDebug(). These messages appear as expected in the terminal when the project is built with qmake but do not appear when the project is built with CMake.

      If the CMake-built executable is run with "Run in terminal" unchecked in the Projects->Run wizard, then qDebug() messages appear correctly in the QtCreator Application Output pane. If the "Run in terminal" is checked, no output appears in either the Application Output pane or the terminal.

      Is there a CMake variable that needs to be set in order to enable terminal output in a CMake console app on Windows?

      Thanks.

      C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 3 Feb 2023, 22:53 last edited by
      #2

      @KenAppleby-0 said in No Console Output To Terminal on Windows When Using CMake:

      Is there a CMake variable that needs to be set in order to enable terminal output in a CMake console app on Windows?

      Yes, see WIN32 keyword for add_executable()

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

      K 1 Reply Last reply 3 Feb 2023, 23:29
      0
      • C Christian Ehrlicher
        3 Feb 2023, 22:53

        @KenAppleby-0 said in No Console Output To Terminal on Windows When Using CMake:

        Is there a CMake variable that needs to be set in order to enable terminal output in a CMake console app on Windows?

        Yes, see WIN32 keyword for add_executable()

        K Offline
        K Offline
        KenAppleby 0
        wrote on 3 Feb 2023, 23:29 last edited by
        #3

        @Christian-Ehrlicher

        Thanks. But I find that adding WIN32 to add_executable (or qt_add_executable) makes no difference.
        The doc you linked to says:
        "If WIN32 is given the property WIN32_EXECUTABLE will be set on the target created."

        This prompted me to look at the Qt-generated entry in the CMakeLists.txt file:

        set_target_properties(application PROPERTIES
            WIN32_EXECUTABLE ON
            MACOSX_BUNDLE ON
        )
        

        So the WIN32_EXECUTABLE is already set...

        But, removing the WIN32_EXECUTABLE ON line, or changing it to WIN32_EXECUTABLE OFF fixes the problem. Debug output appears in the terminal.
        This fits, I think, with the CMake documentation for WIN32_EXECUTABLE: "When this property is set to true the executable when linked on Windows will be created with a WinMain() entry point instead of just main(). This makes it a GUI executable instead of a console application."

        So the answer seems to be to not have either WIN32 in the add_executable or WIN32_EXECUTABLE ON in the set_target_properties?

        C 1 Reply Last reply 4 Feb 2023, 08:58
        0
        • K KenAppleby 0
          3 Feb 2023, 23:29

          @Christian-Ehrlicher

          Thanks. But I find that adding WIN32 to add_executable (or qt_add_executable) makes no difference.
          The doc you linked to says:
          "If WIN32 is given the property WIN32_EXECUTABLE will be set on the target created."

          This prompted me to look at the Qt-generated entry in the CMakeLists.txt file:

          set_target_properties(application PROPERTIES
              WIN32_EXECUTABLE ON
              MACOSX_BUNDLE ON
          )
          

          So the WIN32_EXECUTABLE is already set...

          But, removing the WIN32_EXECUTABLE ON line, or changing it to WIN32_EXECUTABLE OFF fixes the problem. Debug output appears in the terminal.
          This fits, I think, with the CMake documentation for WIN32_EXECUTABLE: "When this property is set to true the executable when linked on Windows will be created with a WinMain() entry point instead of just main(). This makes it a GUI executable instead of a console application."

          So the answer seems to be to not have either WIN32 in the add_executable or WIN32_EXECUTABLE ON in the set_target_properties?

          C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 4 Feb 2023, 08:58 last edited by
          #4

          @KenAppleby-0 said in No Console Output To Terminal on Windows When Using CMake:

          So the answer seems to be to not have either WIN32 in the add_executable or WIN32_EXECUTABLE ON in the set_target_properties?

          Yes - as the documentation states WIN32 creates an application with WinMain() as entry point and therefore has no console.

          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
          0

          1/4

          3 Feb 2023, 22:42

          • Login

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