<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<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;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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]-->
</head>
<body lang="EN-CA" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hello community,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
<p class="MsoNormal">In my example I create a script like this. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">from qgis.PyQt import QtWidgets<o:p></o:p></p>
<p class="MsoNormal">message = "Wait to open the airspace project..."<o:p></o:p></p>
<p class="MsoNormal">msg = QtWidgets.QMessageBox()<o:p></o:p></p>
<p class="MsoNormal">msg.setText(message)<o:p></o:p></p>
<p class="MsoNormal">msg.show()<o:p></o:p></p>
<p class="MsoNormal">qgis.utils.iface.messageBar().pushMessage("Wait", message)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">for i in range(1000):<o:p></o:p></p>
<p class="MsoNormal">    print(i)<o:p></o:p></p>
<p class="MsoNormal">qgis.utils.iface.messageBar().pushMessage("Done", "The process is done")<o:p></o:p></p>
<p class="MsoNormal">msg.setText("The process is done")<o:p></o:p></p>
<p class="MsoNormal">msg.show()<o:p></o:p></p>
<p class="MsoNormal">qgis.utils.iface.messageBar().pushMessage("Done", "The process is done"))<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
<p class="MsoNormal">Then during the loop it displays the variable i.<o:p></o:p></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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></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".<o:p></o:p></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..."<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I modified the scrip by adding QApplication.processEvents() inside the loop and now everything is fine.<o:p></o:p></p>
<p class="MsoNormal">It seems <span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:#232629;background:#F9F8F6">
QGIS3 no longer triggers this event loop and I have to do this explicitly by calling
</span>processEvents from QApplication.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><span style="background:yellow;mso-highlight:yellow">Why QGIS 3 needs to call QApplication.processEvents() and QGIS 2 does not need?</span><o:p></o:p></b></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thank you,<o:p></o:p></p>
<p class="MsoNormal">Marian<o:p></o:p></p>
</div>
<br>
<hr>
<font face="Arial" color="Gray" size="1"><br>
This electronic message, as well as any transmitted files included in the electronic message, may contain privileged or confidential information and is intended solely for the use of the individual(s) or entity to which it is addressed. If you have received
 this electronic message in error please notify the sender immediately and delete the electronic message. Any unauthorized copying, disclosure or distribution of the electronic message is strictly forbidden. NAV CANADA accepts no liability for any damage caused
 by any virus and/or other malicious code transmitted by this electronic communication.<br>
<br>
Le présent message électronique et tout fichier qui peut y être joint peuvent contenir des renseignements privilégiés ou confidentiels destinés à l’usage exclusif des personnes ou des organismes à qui ils s’adressent. Si vous avez reçu ce message électronique
 par erreur, veuillez en informer l’expéditeur immédiatement et supprimez le. Toute reproduction, divulgation ou distribution du présent message électronique est strictement interdite. NAV CANADA n’assume aucune responsabilité en cas de dommage causé par tout
 virus ou autre programme malveillant transmis par ce message électronique.<br>
</font>
</body>
</html>