<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>The trick you need is that you can send a signal from a non-main thread to the gui main-thread.</div><div><br></div><div>In response to the signal you update the model. Put all the information that you need as the signal arg or args.</div><div><br></div><div>I use this idea in scm-workbench to sync the ui to background changes.</div><div><br></div><div>Barry</div><div><br></div><div><br>On 12 Mar 2018, at 21:52, Christian Schulze <<a href="mailto:c.schulze@tlk-thermo.com">c.schulze@tlk-thermo.com</a>> wrote:<br><br></div><blockquote type="cite"><div>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.E-MailFormatvorlage18
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:#1F497D;}
span.E-MailFormatvorlage19
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Hi Florian,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">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?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Christian<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">Von:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Florian Bruhin [<a href="mailto:me@the-compiler.org">mailto:me@the-compiler.org</a>]
<br>
<b>Gesendet:</b> Montag, 12. März 2018 22:13<br>
<b>An:</b> Christian Schulze <<a href="mailto:c.schulze@tlk-thermo.com">c.schulze@tlk-thermo.com</a>><br>
<b>Cc:</b> <a href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a><br>
<b>Betreff:</b> Re: [PyQt] Multithreaded Update of the QStandardItemModel Data<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p><span lang="EN-US" style="font-family:"Calibri",sans-serif">Hi,</span><span lang="EN-US">
<o:p></o:p></span></p>
<p><span lang="EN-US" style="font-family:"Calibri",sans-serif">On Mon, Mar 12, 2018 at 08:59:11PM +0000, Christian Schulze wrote:</span><span lang="EN-US">
<br>
</span><span lang="EN-US" style="font-family:"Calibri",sans-serif">> I'm trying to update the QStandardItemModel data from another thread. This causes several issues:</span><span lang="EN-US">
<br>
</span><span lang="EN-US" style="font-family:"Calibri",sans-serif">></span><span lang="EN-US">
<br>
</span><span lang="EN-US" style="font-family:"Calibri",sans-serif">> [...]</span><span lang="EN-US">
<o:p></o:p></span></p>
<p><span lang="EN-US" style="font-family:"Calibri",sans-serif">QStandardItemModel is part of QtGui, and stuff in QtGui is not</span><span lang="EN-US">
<br>
</span><span lang="EN-US" style="font-family:"Calibri",sans-serif">threadsafe and must be used from the main (GUI) thread only.</span><span lang="EN-US">
<o:p></o:p></span></p>
<p><span lang="EN-US" style="font-family:"Calibri",sans-serif">> It would be great if someone could tell me how to fix this!</span><span lang="EN-US">
<o:p></o:p></span></p>
<p><span lang="EN-US" style="font-family:"Calibri",sans-serif">Your only option is pretty much "don't do this". Why do you need to</span><span lang="EN-US">
<br>
</span><span lang="EN-US" style="font-family:"Calibri",sans-serif">modify a QStandardItemModel from a non-main thread?</span><span lang="EN-US">
<o:p></o:p></span></p>
<p><span lang="EN-US" style="font-family:"Calibri",sans-serif">Florian</span><span lang="EN-US">
<o:p></o:p></span></p>
<p><span lang="EN-US" style="font-family:"Calibri",sans-serif">-- </span><span lang="EN-US"><br>
</span><span style="font-family:"Calibri",sans-serif"><a href="https://www.qutebrowser.org"><span lang="EN-US">https://www.qutebrowser.org</span></a></span><span lang="EN-US" style="font-family:"Calibri",sans-serif"> |
</span><span style="font-family:"Calibri",sans-serif"><a href="mailto:me@the-compiler.org"><span lang="EN-US">me@the-compiler.org</span></a></span><span lang="EN-US" style="font-family:"Calibri",sans-serif"> (Mail/XMPP)</span><span lang="EN-US">
<br>
</span><span lang="EN-US" style="font-family:"Calibri",sans-serif"> GPG: 916E B0C8 FD55 A072 |
</span><span style="font-family:"Calibri",sans-serif"><a href="https://the-compiler.org/pubkey.asc"><span lang="EN-US">https://the-compiler.org/pubkey.asc</span></a></span><span lang="EN-US">
<br>
</span><span lang="EN-US" style="font-family:"Calibri",sans-serif"> I love long mails!
</span><span style="font-family:"Calibri",sans-serif">| <a href="https://email.is-not-s.ms/">
https://email.is-not-s.ms/</a></span> <o:p></o:p></p>
</div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a></span><br><span><a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></span></div></blockquote></body></html>