As an old programmer, when I debug a program, the first option is neither using qDebug()<<“helloworld”, nor using cout<<“helloworld”, not mention QMessageBox::information(this,”hello”,”world”). I’d like to use the old printf function.
But how to use the printf function in a GUI program? For example, you may want to use printf in a slot function in a Qt Widget project. If you just write printf(“hello world”) in a slot function, you will see nothing in the Application Output window in Qt Creator until the debugged program ends. This is because the output of printf is buffered. To make the output of printf display in the Application Output window immediately, you should use:
printf("hello world"); fflush(stdout);
So, as a Qt programmer, you’d better use the Qt statement qDebug()<<“helloworld” which outputs immediately without buffering.
The c++ statement cout<<“helloworld” has the same problem as printf, i.e., the output is buffered and you may only see the output at the end of the debugged program. Furthermore, to use cout, you need to add two lines in your source code:
using namespace std; #include<iostream> .... .... cout<<"hello world"; fflush(stdout);