Details
-
Task
-
Resolution: Out of scope
-
P3: Somewhat important
-
None
-
None
-
None
Description
stdin isn't a socket on Windows thus it is not possible to use QSocketNotifier to read the stdin.
It would be nice to have this written in the documentation:
http://doc.qt.nokia.com/4.7/qsocketnotifier.html#notes-for-windows-users
Related posts:
http://www.qtcentre.org/archive/index.php/t-20357.html
http://lists.trolltech.com/qt-interest/2006-07/thread01097-0.html
The following example works on Linux/Mac but not on Windows:
#include <QCoreApplication> #include <QFile> #include <QSocketNotifier> #include <QDebug> class StdinReader: public QObject { Q_OBJECT public: StdinReader(); public slots: void ReadData(int socket); private: QFile *file; QSocketNotifier *notifier; }; StdinReader::StdinReader() { file = new QFile(this); qDebug() << file->open(stdin,QIODevice::ReadOnly); notifier = new QSocketNotifier(file->handle(),QSocketNotifier::Read,this); qDebug() << notifier->isEnabled(); connect(notifier, SIGNAL(activated(int)), this, SLOT(ReadData(int))); } void StdinReader::ReadData(int socket) { notifier->setEnabled(false); QString string(file->readLine()); qDebug() << "socket " << socket << " read the message " << string; notifier->setEnabled(true); } #include "main.moc" int main(int argc, char **argv) { QCoreApplication app(argc, argv); StdinReader manager; app.exec(); }