On Wed, 17 Aug 2022 at 06:54, Tudorache, Marian via Qgis-user
<[email protected]> wrote:
>
> Hi Chris,
>
>
>
> I read that article and based on it I found out that I need to put 
> processEvents() and I understand the logic in this.
>
>
>
> Someone said:
>
> In more recent QGIS versions the Python console no longer triggers this event 
> loop, as it's often quite dangerous to execute the loop in the middle of 
> other running code.
>
>
>
> It seems somehow QGIS 2.18 was designed to send automatically updates to the 
> GUIs when a loop is running and this capability was eliminated in QGIS 3

That's correct -- there was a forced processEvents in QGIS 2 after
printing anything, but that directly lead to crashes in some
circumstances. processEvents is a potentially very dangerous call, so
now the responsibility is on end users/developers to make sure it's
safe to call after a print.

Nyall



>
> Anyway, thank you for your answer.
>
>
>
> Marian
>
>
>
> From: chris hermansen <[email protected]>
> Sent: August 16, 2022 4:40 PM
> To: Tudorache, Marian <[email protected]>
> Cc: [email protected]
> Subject: [EXT] Re: [Qgis-user] Event loop in QGIS3
>
>
>
> Marian and list, On Tue, Aug 16, 2022 at 12: 02 PM Tudorache, Marian via 
> Qgis-user <qgis-user@ lists. osgeo. org> wrote: Hello community,   A while 
> ago I sent a question about a problem with QMessageBox and message bar does 
> not get updated
>
> Marian and list,
>
>
>
> On Tue, Aug 16, 2022 at 12:02 PM Tudorache, Marian via Qgis-user 
> <[email protected]> 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?
>
>
>
>
>
> Marian, did you read this article?
>
>
>
> https://doc.qt.io/qt-5/qcoreapplication.html#details
>
>
>
> There you will see this:
>
>
>
> The event loop is started with a call to exec(). Long-running operations can 
> call processEvents() to keep the application responsive.
>
>
>
> 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.
>
>
>
> As to why QGIS 2 did not need this, I don't know.
>
>
> --
>
> Chris Hermansen · clhermansen "at" gmail "dot" com
>
> C'est ma façon de parler.
>
>
> ________________________________
>
> 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
> [email protected]
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to