QMessageBox在子线程中
时间: 2023-10-29 21:57:39 浏览: 114
QMessageBox在子线程中的实现是通过自定义的MsgBoxThread类来实现的。这个类继承自QThread类,在构造函数中声明了可在子线程中发射的信号msgbox_sig,并将该信号以阻塞模式(Qt::BlockingQueuedConnection)连接到私有槽函数on_msgbox。由于槽函数的父对象在主线程中创建,这保证了信号msgbox_sig在主线程的事件循环中执行。同时,槽函数on_msgbox采用组色模式连接,使得子线程在调用了QMessageBox的封装函数(如about、aboutQt、information、critical、warning)后会等待主线程的槽函数执行并返回后才会继续执行。这样就可以在子线程中实现简单的UI交互,同时不违反Qt的GUI相关处理必须在主线程中的限制。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Qt在子线程中使用MessageBox](https://blog.csdn.net/weixin_41882459/article/details/108586077)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [关于Qt在子线程中使用QMessageBox的折衷方法](https://blog.csdn.net/JohnYork/article/details/46419185)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文