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

QFileSystemWatcher moved to thread causes exit failure

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 5.14.1
    • None
    • Windows

      If a QFileSystemWatcher is created inside a class which is moved to another thread, then the program finishes unexpectedly when exitting.

      Example: 

      class myClass : public QObject
      {
          Q_OBJECT
      
          QFileSystemWatcher* watcher;
      
      public:
          explicit myClass(QObject *parent = nullptr) : QObject(parent)
          {
              watcher = new QFileSystemWatcher(this);
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QThread t;
          myClass* c = new myClass();
          c->moveToThread(&t);
          QObject::connect(&t, SIGNAL(finished()), c, SLOT(deleteLater()));
          t.start(QThread::NormalPriority);
      
          t.quit();
          t.wait();
      
          return app.exec();
      }
      
      

      If watcher is created without "this" as argument in the constructor it works, but then the watcher is not moved along with myClass to the new thread. 

      Also note that it only fails if app.exec() is called.

       

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

            thiago Thiago Macieira
            sglimberg Stefan Glimberg
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes