QThread doesn't work well

前端 未结 1 1583
轮回少年
轮回少年 2021-01-14 05:07

this\'s the QTread\'s subObject... and concrete it in main Thread....

the Runtime error as follow:

ASSERT failure in QCoreApplication::sendEv

1条回答
  •  鱼传尺愫
    2021-01-14 05:27

    The parent (in this case your MainWindow) lives in a different thread. According to Qt documentation

    You can manually post events to any object in any thread at any time using the thread-safe function QCoreApplication::postEvent(). The events will automatically be dispatched by the event loop of the thread where the object was created. Event filters are supported in all threads, with the restriction that the monitoring object must live in the same thread as the monitored object. Similarly, QCoreApplication::sendEvent() (unlike postEvent()) can only be used to dispatch events to objects living in the thread from which the function is called.

    So as a solution I would propose the following:

    • Define a signal in your PaintThread class
    • connect this signal to the paint() slot in QWidget subclass
    • Emit it in the run() function

    0 讨论(0)
提交回复
热议问题