Corey Austin
Corey Austin

Reputation: 33

QTextStream is not outputting anything, what could I be doing wrong?

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();

Upvotes: 3

Views: 2913

Answers (1)

Emanuele Bezzi
Emanuele Bezzi

Reputation: 1728

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.

Upvotes: 8

Related Questions