[Qgis-user] Event loop in QGIS3
Patrick Dunford
enzedrailmaps at gmail.com
Tue Aug 16 16:15:06 PDT 2022
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?
On 17/08/22 07:02, Tudorache, Marian via Qgis-user wrote:
>
> Hello community,
>
> A while ago I sent a question about a problem with QMessageBox and
> message bar does not get updated during a long process.
>
> In my example I create a script like this.
>
> from qgis.PyQt import QtWidgets
>
> message = "Wait to open the airspace project..."
>
> msg = QtWidgets.QMessageBox()
>
> msg.setText(message)
>
> msg.show()
>
> qgis.utils.iface.messageBar().pushMessage("Wait", message)
>
> for i in range(1000):
>
> print(i)
>
> qgis.utils.iface.messageBar().pushMessage("Done", "The process is done")
>
> msg.setText("The process is done")
>
> msg.show()
>
> qgis.utils.iface.messageBar().pushMessage("Done", "The process is done"))
>
> 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.
>
> Then during the loop it displays the variable i.
>
> At the end of the loop the QMessageBox displays the message "The
> process is done" which is also pushed to the messageBar.
>
> 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.
>
> The print inside the loop displays the I and when the loop is done the
> QMessageBox displays the message "The process is done".
>
> 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..."
>
> I modified the scrip by adding QApplication.processEvents() inside the
> loop and now everything is fine.
>
> It seems QGIS3 no longer triggers this event loop and I have to do
> this explicitly by calling processEvents from QApplication.
>
> *Why QGIS 3 needs to call QApplication.processEvents() and QGIS 2 does
> not need?*
>
> Thank you,
>
> Marian
>
>
> ------------------------------------------------------------------------
>
> 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.
>
> 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.
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info:https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20220817/5ca40d90/attachment-0001.htm>
More information about the Qgis-user
mailing list