1

I'm a real beginner in multithreading. This question is about high-level multithreading in PyQt.

Suppose that a table widget requires much time to be populated because of some single items, making the window unresponsive meanwhile. So I imagine that a responsive window should require a multithreaded solution in this case, where the big calculations (not every ones) are supposed to use separate threads. A simpler version could use a separate thread for every single column instead of single items.

Working examples are really appreciated. Thank you and sorry for my bad english.

EDIT: I removed the 'QtConcurrent' "requisite" from my original question.

4

1 回答 1

2

目前我手头没有一个可行的例子,但我至少可以提供一个建议......

  • 您可以创建一个QThreadQueue.
  • 您的主 gui 线程可以将数据结构放入包含输入参数和目标单元(行/列)的队列中。
  • 线程循环从队列中接收一个新项目,进行计算,然后发出一个类似的信号cellDataReady(row, col, value)

这样您就可以遍历表数据,并且在需要计算的任何时候,只需将其排队即可。

如果您想按照QThreadPool路线进行操作,则所有线程都可以从同一个队列对象中提取。无论哪个下一个空闲的,都会抓取下一个项目,计算并发出。

从线程发出信号将允许您的主 gui 连接到它们并简单地将值添加到表中。

于 2012-09-30T22:44:26.490 回答