PDA

View Full Version : Windows weird console behaviour - stopped displaying output



QTapprentice
2nd December 2016, 10:21
Hi,

I'm currently upgrading and porting a Linux App (Ubuntu 14.04) to windows 7 (Qt Creator 2.1.0 (Qt 4.7.1) + Mingw-w64: --> this is a requisite, not my choice.), and encounter a weird issue.

For debugging reasons i printf lots of info to console, in the linux enviroment it appears in the Qt Creator "Application Output" tab.
In Windows it "used to" appear in an addtional console, and i said "used to" because, the output disappear from one day to another, and i can't find the reason (meaning where did i break it).

In my windows .PRO i have

CONFIG += console

In "Projects --> Run Settings --> Run in Terminal" is checked

WEIRD BEHAVIOUR:
When i run the windows app from Qt Creator, the terminal is opened but no output is displayed (App is working but printfs not printing to console).

If I launch the .exe from windows console (cmd.exe) no output is displayed, in fact, launches the app and the console returns ready for new inputs.

If I launch the .exe form the MSYS2 console I get NEARLY the desired behaviour, i can see the output messages and the App "owns" the terminal untill I close the App, but it has some issues with the flussing of the info. Some lines are ketp in the buffer and not printed untill some other action triggers the buffering flushing.


I suspect that it should be a IDE configuration parameter, but i don't have a clue of what it could be.


Any idea about what's happening?

anda_skoa
3rd December 2016, 12:03
console output on Windows is always problematic, even if it works in can be highly buffered, etc.

Have you tried without the "run in terminal" option? Does it display the output in the Application Output tab?

Alternatively you could try redirecting the output to a file, e.g.

application > file.out

and watch that file (assuming that can somehow be done on Windows).

Cheers,
_

d_stranz
3rd December 2016, 18:46
and watch that file (assuming that can somehow be done on Windows).

If you open the file using Notepad++, it will notify you that the file has changed on disk and ask if you want to reload. It doesn't reload the file automatically in real time, but does watch the file for changes. I use this for watching log and other large output text files. The reload on demand feature is actually more useful than an automatic reload because you are in charge of when the window content gets updated and aren't forced to watch output stream by while you try to read it, as you would with a console window.

QTapprentice
5th December 2016, 10:07
Thanks for the answers to bouth,

This is the behaviour that i get:

run in console CONFIG+=console behaviour
------------------------------------------------------------------------------------------
yes yes open console does not print anything.
no yes does not open console
yes no open console does not print anything.
no no does not open console

If i redirect the output from the cmd.exe "App.exe >> output.txt" does not show anything in the console and the output file is empty.

For now, I can work calling the app from the MSYS2 console and redireccting the output to a file but is way less usefull than watching the output in console in real time as the app has a communications module and i like to see what is going trough the console.

Thanks again for the answers, any other idea would be greatly wellcome.

Lesiok
5th December 2016, 10:22
Read about qInstallMessageHandler (http://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler).

QTapprentice
5th December 2016, 11:05
Thanks for the advice Lesiok,

But, QT 4.7 is a prerequisite and qInstallMessageHandler was introduced in Qt5.0

Also, I have a lot of debug messages printed to stderr in some lowlevel C99 static linked libraries that i would like to see (not sure if qInstallMesageHandler will catch them due to my own ignorance of the function).

Also, all this messages were printing ok in previous versions of the app, (not anymore), wich tells me that it is some Qt Creator config feature that I unwillingly modified.

Any other suggestion will be greatly appreciated.

Lesiok
5th December 2016, 11:22
In Qt 4 this function is qInstallMsgHandler (http://doc.qt.io/qt-4.8/qtglobal.html#qInstallMsgHandler).

QTapprentice
5th December 2016, 11:57
Ok, i did try the qInstallMsgHandler but to no avail... it behaves like my own debugging functions.

Only prints out if i call the exe from the MSYS2 console and buffers contents.

The console that opens from the QtCreator doesn't show anything.