PDA

View Full Version : console output on windows and ubuntu



hannesvdc
11th December 2010, 23:35
Hi all,

I'm quite new to Qt and i have a question about something whether or not
something is normal:

I made a very simple main function:


#include <QtGui/QApplication>
#include <iostream>

int main( int argc, char* argv[] ){
QApplication app( argc, argv);
std::cout<<"initialisation successful!";
return app.exec();
}


When i run it( compiling gave no errors), nothing is printed to the terminal
in ubuntu, unless i use std::cout.flush(), then it is printed. But in windows,
nothing is printed at all.

Something else is that my application never ends.

Is this normal?

hannesvdc

tbscope
11th December 2010, 23:42
unless i use std::cout.flush()
That's because the output is buffered.


But in windows, nothing is printed at all.
You need to add "CONFIG += console" to your .pro file.


Something else is that my application never ends.
That is because you start the application event loop. This will run for ever until you tell it to stop.

wysota
11th December 2010, 23:43
This is perfectly normal behaviour.

nothing is printed to the terminal
in ubuntu, unless i use std::cout.flush(), then it is printed.
Streams are buffered by default in unix systems so you have to flush a stream (e.g. by sending it a newline character - \n) to empty the buffers.

But in windows, nothing is printed at all.
Add CONFIG+=console to your project file and rerun qmake.

Edit: Beaten to it :)