Is it possible to use cin with Qt?

grant picture grant · Feb 23, 2010 · Viewed 21.2k times · Source

Is it possible to use cin in Qt? I can use cout but cannot find examples of how to use cin within a Qt console application.

Answer

sivabudh picture sivabudh · Jun 10, 2010

I tested out Kaleb Pederson's answer, and found a more consise way than the solution he presented (though I have to thank him for pointing me to the right direction):

QTextStream qtin(stdin); 
QString line = qtin.readLine();  // This is how you read the entire line

QString word;
qtin >> word;    // This is how you read a word (separated by space) at a time.

In other words, you don't really need QFile as your middleman.