如何在Python中初始化QT线程
根据网上看到的示例,我创建了一个 Worker
线程。我正在寻找一个线程来运行我的 GUI,同时一个线程执行我的代码。 Worker
线程的定义如下:
class Worker(QThread):
def __init__(self, parent = None):
QThread.__init__(self, parent)
self.exiting = False
self.size = QSize(0, 0)
def __del__(self):
self.exiting = True
self.wait()
非常简单。在我的 Window
类中,我在 __init__
函数中添加了这一行:self.thread = Worker()
。然而,此后我再也没有对 self.thread 做任何事情。我应该用它做什么?这似乎没有其他线程机制那么好。
As per examples seen online, I've created a Worker
thread. I'm looking for a thread to run my GUI while one thread executes my code. Worker
thread is defined as:
class Worker(QThread):
def __init__(self, parent = None):
QThread.__init__(self, parent)
self.exiting = False
self.size = QSize(0, 0)
def __del__(self):
self.exiting = True
self.wait()
pretty simple. Within my Window
class, I have this line in the __init__
function: self.thread = Worker()
. However, I never do anything with that self.thread afterwards. What am I supposed to be doing with it? This does not seem to be laid out as nicely as other threading mechanisms..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您正在查看此处的示例?但该示例确实“随后对该线程执行某些操作”——它在 Worker 类中挂钩方法来响应线程启动和结束时发送的信号它定义了一个
run
方法来绘制随机星星等。不确定您认为这是如何“布局”的错误?I imagine you're looking at the example here? But that example does "do something with that thread afterwards" -- it hooks up methods to respond to the signals the thread sends when it starts and finishes, in the
class Worker
it defines arun
method that draws random stars , etc etc. Not sure what you think is wrong with how this is "laid out"?