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

QFileSystemWatcher moved to thread causes exit failure

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.14.1
    • Fix Version/s: None
    • Labels:
      None
    • Platform/s:
      Windows

      Description

      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.

       

        Attachments

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

          Activity

            People

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

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes