Qt console application does not show cmd window in Qt Creator

If you create a Qt console application in Qt creator, and debug it in Qt Creator, you’ll find no cmd window is displayed. You check the .pro file and find “CONFIG += console” is right there. You may think since you debug the project in Qt Creator, it may redirect the console output to the “Application Output” tab in Qt Creator. But when you click that tab, you still see nothing output there by your printf statements. Whenever you click “Run” or “Start debugging of startup project”, there is no content shown in the “Application Output” tab. Your application seems to hung. You think maybe there is a problem with your program, and you start to check the source code to find the problem. Unfortunately, this problem has nothing to do with your source code. It is invented to bring some inconvenience for you to develop a console application.

If you change “printf” to “qDebug()”, the situation would be better. You will see the output of qDebug() in theĀ  “Application Output” tab in Qt Creator, although there is still no DOS window displayed during the run. The problem is qDebug() outputs a line-break automatically even you do not want it at each execution. So, you have no choice but to use printf. You can somewhat alleviate the cmd window not showing problem by adding a “fflush(stdout);” line after printf statements. Now, you will see the output in theĀ  “Application Output” tab in Qt Creator when clicking “Run”, but still nothing when clicking “Start debugging of startup project”, and still no cmd window.

The final solution would adjust the project settings: Click “Project” on the left vertical bar, under “Build & Run”/your current build kits, click “Run”, tick the “Run in terminal” checkbox on the right part of the window under the “Run” section. Now, you can see the cmd window show up whether you click “Run” or “Start debugging of startup project”, and the output of printf will be shown in the cmd window(not redirected to the “Application Output” tab in Qt Creator any more).

The problem is introduced in the late Qt version and does not occur in old Qt versions.

 

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Leave a Reply