QTextStrem stdin dont work?
-
The question is probably quite trivial,
but I can't find a solution.
It doesn't seem to work for other users.
I can't enter my name.Can you help me please
#include <QtCore/QCoreApplication> #include <QTextStream> #include <QString> int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QTextStream qout (stdout); QTextStream qin (stdin); qin.flush();//Does it make sense? to clear memory directly? Should actually be ller. qout << "Please enter your name: "; QString inpu =qin.readLine(); Qt::endl; qout <<" Welcome " << inpu <<Qt::endl; return app.exec(); }
-
@PeterS Hello!
Try this. And keep in mind that it is not possible to write input values in Qt Creator.// QCoreApplication app(argc, argv); QTextStream qout(stdout); QTextStream qin(stdin); // qin.flush();//Does it make sense? to clear memory directly? Should actually be ller. qout << "Please enter your name: "; qout.flush(); // clears the keyboard buffer qin.skipWhiteSpace(); // Remove white characters that interrupt QString inpu = qin.readLine(); // Qt::endl; // qout <<" Welcome " << inpu <<Qt::endl; qout << " Welcome " << inpu; // return app.ex
-
@PeterS Hello!
Try this. And keep in mind that it is not possible to write input values in Qt Creator.// QCoreApplication app(argc, argv); QTextStream qout(stdout); QTextStream qin(stdin); // qin.flush();//Does it make sense? to clear memory directly? Should actually be ller. qout << "Please enter your name: "; qout.flush(); // clears the keyboard buffer qin.skipWhiteSpace(); // Remove white characters that interrupt QString inpu = qin.readLine(); // Qt::endl; // qout <<" Welcome " << inpu <<Qt::endl; qout << " Welcome " << inpu; // return app.ex
@posktomten
Thank you.I don't think on the fact thats is not possible to make inputs in QtCreator. Now it works fine.
-
-
@posktomten
Thank you.I don't think on the fact thats is not possible to make inputs in QtCreator. Now it works fine.
@PeterS said in QTextStrem stdin dont work?:
I don't think on the fact thats is not possible to make inputs in QtCreator.
What does this mean? Where have you be running your application, seeing its output, and trying to input? You certainly have not said so previously. Qt Creator? Are you simply looking at the Application Output there, which as it says simply displays output? Have you run your application outside of Creator in a terminal? If that works, you will need to tell Creator you want it to open a terminal for input/output when you run your program from there.
-
@PeterS said in QTextStrem stdin dont work?:
I don't think on the fact thats is not possible to make inputs in QtCreator.
What does this mean? Where have you be running your application, seeing its output, and trying to input? You certainly have not said so previously. Qt Creator? Are you simply looking at the Application Output there, which as it says simply displays output? Have you run your application outside of Creator in a terminal? If that works, you will need to tell Creator you want it to open a terminal for input/output when you run your program from there.
-
@JonB Yes , you are right. I has only looking in the Application Output, Inside a terminal it runs fine. Thanks you.
-
@PeterS OK, hopefully you have found in Creator where you can set so this application always gets a terminal for it to run in.
Hi,
Out of curiosity, why are you calling
app.exec();
since the rest of the logic will be done by the time you reach that line ? -
Hi,
Out of curiosity, why are you calling
app.exec();
since the rest of the logic will be done by the time you reach that line ?@SGaist I commented it out.