QTextStream::readLine() returns null
-
I am using QT6.8.2 on windows. In a Qt console app the following readLine does not wait for user input and returns "" immediately. Can somebody advise.
#include <QCoreApplication>
#include <QTextStream>
#include <QDebug>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);qDebug() << "\nType in your search phrase:\n"; QTextStream s(stdin); const auto phrase = s.readLine(); qDebug() << " you entered" << phrase; return a.exec();
}
-
@PaulHuber
Also read through Application output does not wait for QTextStream readLine();. Per the last post there, are you running this from Command Prompt or from Creator? -
Try with bitshift operator:
QString input; s >> input;
-
I am using QT6.8.2 on windows. In a Qt console app the following readLine does not wait for user input and returns "" immediately. Can somebody advise.
#include <QCoreApplication>
#include <QTextStream>
#include <QDebug>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);qDebug() << "\nType in your search phrase:\n"; QTextStream s(stdin); const auto phrase = s.readLine(); qDebug() << " you entered" << phrase; return a.exec();
}
@PaulHuber
Also read through Application output does not wait for QTextStream readLine();. Per the last post there, are you running this from Command Prompt or from Creator? -
@PaulHuber
Also read through Application output does not wait for QTextStream readLine();. Per the last post there, are you running this from Command Prompt or from Creator? -
-
@JonB Tks issue resolved. Running from the command prompt functions normally. The application output window from creator does not allow user input.
@PaulHuber
Yes, as per the answer there. The Application Output pane is only for output. I believe current Creator has an alternative "terminal setting" these days, which allows a genuine terminal with input as well as output allowed if you want to use it that way.