[PyQt] Multithreaded Update of the QStandardItemModel Data

Christian Schulze c.schulze at tlk-thermo.com
Mon Mar 12 22:35:44 GMT 2018


Great! The issues are fixed! Thanks!

The updated example is attached. I’ll try implement it in my code.

Christian


Von: Barry [mailto:barry at barrys-emacs.org]
Gesendet: Montag, 12. März 2018 23:03
An: Christian Schulze <c.schulze at tlk-thermo.com>
Cc: Florian Bruhin <me at the-compiler.org>; pyqt at riverbankcomputing.com
Betreff: Re: [PyQt] Multithreaded Update of the QStandardItemModel Data

The trick you need is that you can send a signal from a non-main thread to the gui main-thread.

In response to the signal you update the model. Put all the information that you need as the signal arg or args.

I use this idea in scm-workbench to sync the ui to background changes.

Barry


On 12 Mar 2018, at 21:52, Christian Schulze <c.schulze at tlk-thermo.com<mailto:c.schulze at tlk-thermo.com>> wrote:
Hi Florian,

I need to update many items continuously. Several rows are updated at least once per second. For some use cases I have 20000 rows in total. I prepared all the data (new/modified/removed items), so that hardly any calculation is done in the main thread.

However, the main thead seems to be blocked for too long. The GUI seems to freeze for a short moment when I update the data. This is really annoying when you’re working with the application and I’d like to fix that.

I had expected that I’m allowed to modify the item model, since the GUI thread only reads data. I don’t care if an intermediate state is displayed.

So I need to implement my own threadsafe item model? Is any python based item model implementation threadsafe due to the GIL? Is the interaction of python and C++ fast enough to do this?

Thanks,
Christian


Von: Florian Bruhin [mailto:me at the-compiler.org]
Gesendet: Montag, 12. März 2018 22:13
An: Christian Schulze <c.schulze at tlk-thermo.com<mailto:c.schulze at tlk-thermo.com>>
Cc: pyqt at riverbankcomputing.com<mailto:pyqt at riverbankcomputing.com>
Betreff: Re: [PyQt] Multithreaded Update of the QStandardItemModel Data


Hi,

On Mon, Mar 12, 2018 at 08:59:11PM +0000, Christian Schulze wrote:
> I'm trying to update the QStandardItemModel data from another thread. This causes several issues:
>
> [...]

QStandardItemModel is part of QtGui, and stuff in QtGui is not
threadsafe and must be used from the main (GUI) thread only.

> It would be great if someone could tell me how to fix this!

Your only option is pretty much "don't do this". Why do you need to
modify a QStandardItemModel from a non-main thread?

Florian

--
https://www.qutebrowser.org | me at the-compiler.org<mailto:me at the-compiler.org> (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
         I love long mails! | https://email.is-not-s.ms/
_______________________________________________
PyQt mailing list    PyQt at riverbankcomputing.com<mailto:PyQt at riverbankcomputing.com>
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180312/7b3d7c61/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MultithreadedItemModelUpdate2.py
Type: application/octet-stream
Size: 2110 bytes
Desc: MultithreadedItemModelUpdate2.py
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180312/7b3d7c61/attachment-0001.obj>


More information about the PyQt mailing list