<div dir="ltr"><div dir="ltr">Marian and list,<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 16, 2022 at 12:02 PM Tudorache, Marian via Qgis-user <<a href="mailto:qgis-user@lists.osgeo.org">qgis-user@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg6665883713765490951">





<div style="overflow-wrap: break-word;" lang="EN-CA">
<div class="gmail-m_6665883713765490951WordSection1">
<p class="MsoNormal">Hello community,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">A while ago I sent a question about a problem with QMessageBox and message bar does not get updated during a long process.<u></u><u></u></p>
<p class="MsoNormal">In my example I create a script like this. <u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">from qgis.PyQt import QtWidgets<u></u><u></u></p>
<p class="MsoNormal">message = "Wait to open the airspace project..."<u></u><u></u></p>
<p class="MsoNormal">msg = QtWidgets.QMessageBox()<u></u><u></u></p>
<p class="MsoNormal">msg.setText(message)<u></u><u></u></p>
<p class="MsoNormal">msg.show()<u></u><u></u></p>
<p class="MsoNormal">qgis.utils.iface.messageBar().pushMessage("Wait", message)<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">for i in range(1000):<u></u><u></u></p>
<p class="MsoNormal">    print(i)<u></u><u></u></p>
<p class="MsoNormal">qgis.utils.iface.messageBar().pushMessage("Done", "The process is done")<u></u><u></u></p>
<p class="MsoNormal">msg.setText("The process is done")<u></u><u></u></p>
<p class="MsoNormal">msg.show()<u></u><u></u></p>
<p class="MsoNormal">qgis.utils.iface.messageBar().pushMessage("Done", "The process is done"))<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">When I run the scrip in QGIS 2.18 the QMessageBox displays first the message "Wait to open the airspace project...". The same message is pushed to messageBar.<u></u><u></u></p>
<p class="MsoNormal">Then during the loop it displays the variable i.<u></u><u></u></p>
<p class="MsoNormal">At the end of the loop the QMessageBox displays the message "The process is done" which is also pushed to the messageBar.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">When I run the same scrip on QGIS 3 the QMessageBox is empty. The message "Wait to open the airspace project..." is not displayed by QMessageBox nor by messageBar.<u></u><u></u></p>
<p class="MsoNormal">The print inside the loop displays the I and when the loop is done the QMessageBox displays the message "The process is done".<u></u><u></u></p>
<p class="MsoNormal">The messageBar displays also the message "The process is done". And after a while it displays the initial message "Wait to open the airspace project..."<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I modified the scrip by adding QApplication.processEvents() inside the loop and now everything is fine.<u></u><u></u></p>
<p class="MsoNormal">It seems <span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:rgb(35,38,41);background:rgb(249,248,246) none repeat scroll 0% 0%">
QGIS3 no longer triggers this event loop and I have to do this explicitly by calling
</span>processEvents from QApplication.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><b><span style="background:yellow none repeat scroll 0% 0%">Why QGIS 3 needs to call QApplication.processEvents() and QGIS 2 does not need?</span><u></u><u></u></b></p>
<p class="MsoNormal"><u></u> </p></div></div></div></blockquote><div><br></div><div>Marian, did you read this article?</div><div><br></div><div><a href="https://doc.qt.io/qt-5/qcoreapplication.html#details">https://doc.qt.io/qt-5/qcoreapplication.html#details</a></div><div><br></div><div>There you will see this:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>The event loop is started with a call to <a href="https://doc.qt.io/qt-5/qcoreapplication.html#exec">exec</a>(). Long-running operations can call <a href="https://doc.qt.io/qt-5/qcoreapplication.html#processEvents">processEvents</a>() to keep the application responsive.</div></blockquote><div><br></div><div>In your case, your "long-running operation" is your for loop.  And it is not QGIS3 that has the responsibility to trigger processEvents() but your own long-running operation, at least the way I'm reading this.<br></div><div><br></div>As to why QGIS 2 did not need this, I don't know.<br clear="all"></div><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Chris Hermansen · clhermansen "at" gmail "dot" com<br><br>C'est ma façon de parler.</div></div></div>