QTextStream doesn't output anything, what can I do wrong?

I am trying to use a QTextStream to output to stdout, but nothing happens unless I enter a character. I tried to enable cstdlib, this did not work either.

Note. I tried to remove all links to my stdin QTextStream and the result 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();
+3
source share
1 answer

You need to manually clear the buffer after each button click 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();

As an alternative, an addition is also added << endl.

+8
source

All Articles