Skip to content

CopperSpice Journal

CopperSpice Journal

Console Output (Example 44)

Posted on April 30, 2024May 6, 2024 By Barbara Geller

Debug and warning messages can be sent to a separate window which is independent of the application main window. This is normally used for testing or debugging purposes. The information in this post explains how to enable the console output for a CopperSpice application.

What is a Console Window

The functions qDebug(), qWarning(), and printf() can be used to output informative messages for the developer or user. Text can also be sent to an output stream using std::cout or std::cerr. The result will be sent to either standard output or standard error. The exact location depends on how the specific function or stream was configured.

The operating system is responsible for choosing where the text will be physically displayed or sent. The most common location is a console or terminal window.

Users can start a program with additional parameters to redirect the standard output to a file and bypass sending messages to a console screen.

Console or Terminal on Unix

When you start an application from a shell window all of the debugging output will be displayed in the terminal for that shell. If the application is started from an icon there is no terminal so all debugging messages will be discarded. The same program is used in both cases, the only difference is how the user starts the application.

How to Disable the Console on Windows

For a Windows application the developer must choose at compile time if a console or terminal window should be displayed when the program is started. The default action is to generate a console where the debugging messages will be displayed.

The following fragment is required in your CMake file to turn off and disable the console window from opening. The commands on lines 7 through 11 pertain to MSVC and the commands on lines 15 through 17 are used when compiling with MinGW.

// fragment of the CMakeLists.txt for a CS project

if (CMAKE_SYSTEM_NAME MATCHES "Windows")  

   if (MSVC)
      # disables the console window for MSVC
      target_link_options(KitchenSink
         PRIVATE
         /subsystem:windows
         /entry:mainCRTStartup
      )

   else()
      # disables the console window for MinGW
      target_link_libraries(KitchenSink
         -mwindows
      )

   endif()

endif()
Uncategorized

Post navigation

Previous Post: Source Code  (Gui Example 43)
Next Post: Source Code  (Gui Example 45)
  • CopperSpice Journal Homepage
    • Table of Contents
    • Example Source Code
    • Discussion Forum
  • CopperSpice Homepage
  • Github Repository
  • Videos About C++

Post comments or questions on our CopperSpice Forum

Copyright © 2021-2025 CopperSpice