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.

2
  • 1
    QtConcurrent is not present in PyQt. Probably because it uses templates and that's hard to wrap in Python.
    – Avaris
    Sep 29, 2012 at 18:20
  • Thank you, I removed it from my question.
    – iacopo
    Nov 17, 2013 at 0:06

1 Answer 1

2

I don't have a working example on hand for you at the moment, but I can at least offer a suggestion...

  • You can create a QThread (or a pool) that loops on a Queue.
  • Your main gui thread can place a data structure into the queue that includes the input parameters, and the destination cell (row/col).
  • The thread loop receives a new item from the queue, does the calculation, and then emits a signal like cellDataReady(row, col, value).

This way you can run through the table data and at any time when a calculation is needed, just queue it up.

If you want to do it the QThreadPool route, all of the threads can be pulling from the same queue object. Whichever one is free next will grab the next item, calculate, and emit.

Emitting signals from the threads will allow your main gui to connect to them and simply add the value into the table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.