zl程序教程

您现在的位置是:首页 >  其他

当前栏目

moveToThread的根本目的还是为了处理QObject的事件循环(如果为空指针的话,当前对象的所有的事件都不处理了),看官方说明就知道了

事件循环官方对象 处理 说明 所有 知道
2023-09-11 14:19:08 时间

Changes the thread affinity for this object and its children. The object cannot be moved if it has a parent. Event processing will continue in the targetThread.

To move an object to the main thread, use QApplication::instance() to retrieve a pointer to the current application, and then use QApplication::thread() to retrieve the thread in which the application lives. For example:

myObject->moveToThread(QApplication::instance()->thread());


http://doc.qt.io/archives/qt-4.8/qobject.html#moveToThread