<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Thanks for this question. I had the same issue in my code, but
      running a console script in the Qgis application, printing to the
      console output would achieve the same thing. Is this applicable to
      scripts that run in the console?<br>
    </p>
    <div class="moz-cite-prefix">On 17/08/22 07:02, Tudorache, Marian
      via Qgis-user wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:YQXPR01MB3831AD5DAB8B7404A2C56ED6E66B9@YQXPR01MB3831.CANPRD01.PROD.OUTLOOK.COM">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style>@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;}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;}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">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 size="1" face="Arial" color="Gray"><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>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
Qgis-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
</pre>
    </blockquote>
  </body>
</html>