Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-15457

Add to the documentation that QSocketNotifier does not work with stdin on Windows

    XMLWordPrintable

Details

    • Task
    • Resolution: Out of scope
    • P3: Somewhat important
    • None
    • None
    • Documentation
    • 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();
      }
      
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            docteam Qt Documentation Team
            sanonymous Nokia Qt Support (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes