QTextStream is not outputting anything, what could I be doing wrong?
c++, qt
Solution
You have to manually flush the buffer after each time you push something in the stream:
QTextStream out(stdout);
out << "Please enter login username and password\n";
out.flush();
QTextStream in(stdin);
out << "username:";
out.flush();
QString username = in.readLine();
out << "password:";
out.flush();
QString password = in.readLine();
Alternatively, appending `<< endl` also works.
Problem
I'm trying to use QTextStream to output to stdout, but nothing happens unless I enter a character. I have tried including cstdlib, this did not work either. Note: I tried removing all references to my stdin QTextStream and output worked fine. ``` #include <QTextStream> QTextStream out(stdout); out << "Please enter login username and password\n"; QTextStream in(stdin); out << "username:"; QString username = in.readLine(); out << "password:"; QString password = in.readLine(); ```