如何告诉我的主 GUI 等待工作线程? [英] How do I tell my main GUI to wait on a worker thread?

查看:58
本文介绍了如何告诉我的主 GUI 等待工作线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功将 PyQT4 GUI 中的昂贵例程外包给工作人员 QThread,以防止 GUI 无响应.但是,我希望 GUI 等到工作线程完成处理才能继续执行自己的代码.

I have successfully outsourced an expensive routine in my PyQT4 GUI to a worker QThread to prevent the GUI from going unresponsive. However, I would like the GUI to wait until the worker thread is finished processing to continue executing its own code.

我立即想到的解决方案是让线程在完成时发出信号(据我所知,QThreads 已经这样做了),然后在执行其余代码之前在主窗口中查找此信号.这是被黑了吗?

The solution that immediately comes to my mind is to have the thread emit a signal when complete (as I understand, QThreads already do this), and then look for this signal in the main window before the rest of the code is executed. Is this hacked?

我知道 QThread 提供了这里描述的 wait() 函数,但我不清楚用法.我想我想在主线程上调用它,但我不确定如何在我的应用程序中调用它...?

I know QThread provides the wait() function described here , but the usage is unclear to me. I think I want to call this on the main thread, but I'm not sure how to call that in my app...?

推荐答案

这是一个非常糟糕的计划.拆分线程操作之前"和线程操作之后".线程后操作"应该是由线程可以发出信号的 QueuedConnection 触发的插槽.

This is a really bad plan. Split up the 'before thread action' and 'after thread action'. The 'after thread action' should be a slot fired by a QueuedConnection that the thread can signal.

不要在 GUI 事件处理程序中等待!

Do not wait in GUI event handlers!

这篇关于如何告诉我的主 GUI 等待工作线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆