QThread ASSERT failure in QMutexLocker: “QMutex pointer is misaligned”,

前端 未结 3 537
广开言路
广开言路 2021-01-23 16:40

Im trying to create an uploader that will create new threads and in every thread I have a QNetworkAccessManager. All the uploader threads have a reference to a shared list and w

3条回答
  •  广开言路
    2021-01-23 16:46

    This is probably because the order some object in your application is created. I would recommend inherit from QObject instead of QThread, and move the object to a worker thread instead (QObject::moveToThread()). Also move any code that is initialized in FileUploader to a separate slot in FileUploader, say init(). Invoke init (QMetaObject::invokeMethod()) when the thread is running (after calling start on the worker thread). E.g.:

    FileUploader : public QOject
    {
    ...
    public slots:
    void init() { Foo *foo = new Foo(this); }
    }
    
    // main thread
    QThread worker;
    FileUploader *fup = new FileUploader();
    fup->moveToThread(&worker);
    worker.start();
    QMetaObject::invokeMethod(fup, "init", Qt::QueuedConnection); 
    //
    

提交回复
热议问题