Console window not displaying
-
Hello,
I just migrated from Qt 5.11.2 with MinGW 5.7.1 32 bit to Qt 6.2.3 MinGW 9.0.0 64 bit on Windows 10. I created the simplest possible project: A console application that just 'printf("Test"). The program compiles and runs, but the console window never displays. I created an empty, default widget application. It compiles, runs and displays the mainwindow. Any suggestions? -
Hi, you're talking about running a console program from inside Qt Creator, right?
This behavior is not a bug, it's a feature in Qt Creator version 6. (Haven't tested Qt Creator version 7 yet but I expect the same as in version 6).In earlier versions of Qt Creator, for example 5.0.1, a console window appears as you mention. But in version 6 Qt Creator instead tries to route your printf() calls to the Application Output window in Qt Creator (so that your printf() calls behave more or less like calls to qDebug())
However this routing to the Application Output window usually never shows up due to the exec() call at the end of main().
I.e. before version 6 of Qt Creator you could use a simple console program like this:#include <QCoreApplication> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); printf("Test"); return a.exec(); }
but now you have to remove the exec() call:
#include <QCoreApplication> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); printf("Hello Qt Creator 6"); // return a.exec(); }
for the printf() call to show up in the Application Output window.
Edit: Good news! I jusr saw that you can revert to the old behavior (displaying a console window) via an option in the Build & Run, General tab. Look close to the bottom for the "Default for "Run in Terminal" and change it to "Enabled", voila :-)
-
@hskoglund said in Console window not displaying:
Edit: Good news! I jusr saw that you can revert to the old behavior (displaying a console window) via an option in the Build & Run, General tab. Look close to the bottom for the "Default for "Run in Terminal" and change it to "Enabled", voila :-)
Yes! It works, what a pleasure to see this good ol' black window again! Merci beaucoup !
Jean-Claude -
@hskoglund thank you for the answer! It helped me much!
-
You need to make the "Projects" tab active , then choose "Build & Run". In the "Run Settings" section you will find the checkbox to enable "Run in terminal". This is for Qt Creator version 10.0.0.
-
@Don-Kemlage This method works, but is there no better way?
-
@Elliot_foo said in Console window not displaying:
@Don-Kemlage This method works, but is there no better way?
There are other ways:
- Use
qDebug()
instead ofprintf()
, OR - Call
fflush(stdout);
after printf()
- Use
-
@hskoglund Oh man I need that, thank you!
-
@marcolino said in Console window not displaying:
Instead it works in the terminal in bottom of QT
That IS the embedded console