{"id":2590,"date":"2024-04-30T09:00:43","date_gmt":"2024-04-30T17:00:43","guid":{"rendered":"https:\/\/journal.copperspice.com\/?p=2590"},"modified":"2024-05-06T08:48:21","modified_gmt":"2024-05-06T16:48:21","slug":"source-code-gui-example-44","status":"publish","type":"post","link":"https:\/\/journal.copperspice.com\/?p=2590","title":{"rendered":"Console Output&nbsp;(Example 44)"},"content":{"rendered":"\n<p>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. <\/p>\n\n\n\n<h3>What is a Console Window<\/h3>\n\n\n\n<p>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 <strong>standard output<\/strong> or <strong>standard error<\/strong>. The exact location depends on how the specific function or stream was configured.<br><br>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.   <br><br>Users can start a program with additional parameters to redirect the standard output to a file and bypass sending messages to a console screen.<\/p>\n\n\n\n<h3>Console or Terminal on Unix<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3>How to Disable the Console on Windows<\/h3>\n\n\n\n<p>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. <br><br>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 <strong>MSVC<\/strong> and the commands on lines 15 through 17 are used when compiling with <strong>MinGW<\/strong>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: fsharp; title: ; notranslate\" title=\"\">\n\/\/ fragment of the CMakeLists.txt for a CS project\n\nif (CMAKE_SYSTEM_NAME MATCHES &quot;Windows&quot;)  \n\n   if (MSVC)\n      # disables the console window for MSVC\n      target_link_options(KitchenSink\n         PRIVATE\n         \/subsystem:windows\n         \/entry:mainCRTStartup\n      )\n\n   else()\n      # disables the console window for MinGW\n      target_link_libraries(KitchenSink\n         -mwindows\n      )\n\n   endif()\n\nendif()\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>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. <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts\/2590"}],"collection":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2590"}],"version-history":[{"count":82,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts\/2590\/revisions"}],"predecessor-version":[{"id":2810,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts\/2590\/revisions\/2810"}],"wp:attachment":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}