Search code examples
c++qtqdebug

Collect user input using qDebug


I have been wondering if it is possible to collect user input using the qDebug() statement in Qt C++.

I tried do it like in the std C++ code like:

qDebug() >> myvar;

but it didn't work.

How can I read from stdin using Qt?


Solution

  • qDebug is used to make output to stderr. If you want to read from stdin using Qt, you should use QTextStream:

    #include <stdio.h>
    
    QTextStream in(stdin);
    
    QString line;
    in >> line;