In Qt, the most used is the GUI page, but the GUI is slow, some small test may wish to use the console first, of course, in QT can directly use cout, cin these. It may not be compatible with some types of QT, such as Qbytearray. Looked up on the internet, found that the following methods can be used to output.
You first need to include the following header files:
#include <QTextStream>
#include <stdio.h>
Then, before using CIN, cout, Cerr, create the following variables:
Qtextstream Cin (stdin, qiodevice::readonly);
Qtextstream cout (stdout, qiodevice::writeonly);
Qtextstream Cerr (stderr, qiodevice::writeonly);
Among them, Qtextstream is a very useful string processing class, it can make a string or character-based device, file processing becomes very convenient.
You can then use the CIN, cout, Cerr classes in the qstring environment, just like normal C + +. It is important to note that such cin, cout, Cerr and we encountered in the traditional C + + is a little different, that is, you cout a qstring, the default is not directly output, it is generally necessary to wait until the cout buffer full, before the terminal output of the internal string If you want to see the output immediately after cout, you can either output a endl after the output, or call cout's internal method flush, forcing the condition buffer, for example:
QString str;
str = "Hello world!";
cout<<str;
Cout.flush ();
cin>>str;
cout<<str<<endl;
Qt using cout, CIN, Cerr