When I run the basic Qt code in the below snippet, which is supposed to output "Please enter your name: ", wait for me to enter my name, and then print "Hello < name >", both outputs are written simultaneously, even though it is supposed to prompt for input before the 2nd output is printed.
#include <QCoreApplication>
#include <QTextStream>
void do_qt(){
QTextStream qin(stdin);
QTextStream qout(stdout);
qout << "Please enter your namne: ";
qout.flush();
QString name = qin.readLine();
qout << "Hello " << name;
qout.flush();
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
do_qt();
return a.exec();
}
Output :
Please enter your namne: Hello
What is going on here?
I am using:
- Qt 6.5.2
- Qt Creator
- CMake
- Ubuntu 20.