Qt之線程使用問題

使用線程,遇到了一個問題,release模式正常,但debug模式崩潰,報如下錯誤:

ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 171107d8. Receiver '' (of type 'xxx') was created in thread 1709e0c0", file kernel\qcoreapplication.cpp, line 541
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.

線程使用的方法如下:

   Worker* worker = new Worker(this);
    connect(worker,SIGNAL(finished(QStringList)),this,SLOT(slotFinished(QStringList)),Qt::QueuedConnection);
    QThreadPool::globalInstance()->start(worker);

其中worker繼承自QRunnable,用來獲取磁盤文件列表。

從代碼來看,並非是線程中更新UI造成的。

經過諮詢,是兩個線程公用一個對象造成的,即跨線程使用對象。最終發現是work本身跨線程使用了,即worker初始化時父對象不能傳this.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章