Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
Not a tutorial, but putting this here in case I need to refer back in future. While developing a Golang-Qt application recently, I found out that UI elements such as progress bar or progress dialog will not be updated without this line:
core.QCoreApplication_ProcessEvents(core.QEventLoop__AllEvents)
Why? Basically, a graphical user interface(GUI) Qt application needs to update/redraw itself....but doing so every second can be a resource hogging process.
From http://doc.qt.io/qt-5/qcoreapplication.html#processEvents:
In the event that you are running a local loop which calls this function continuously, without an event loop, the DeferredDelete events will not be processed. This can affect the behaviour of widgets, e.g. QToolTip, that rely on DeferredDelete events to function properly. An alternative would be to call sendPostedEvents() from within that local loop.
Calling this function processes events only for the calling thread.
Therefore, need to invoke the core.QCoreApplication_ProcessEvents(core.QEventLoop__AllEvents)
function to get Qt to update the UI elements such as a progress bar.
References:
http://doc.qt.io/qt-5/qcoreapplication.html#processEvents
https://www.socketloop.com/tutorials/golang-qt-progress-dialog-example
See also : Golang : Qt progress dialog example
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+10.6k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+6.9k Default cipher that OpenSSL used to encrypt a PEM file
+13.5k Facebook PHP getUser() returns 0
+6.1k Golang : How to verify input is rune?
+8.3k Prevent Write failed: Broken pipe problem during ssh session with screen command
+7k Golang : How to solve "too many .rsrc sections" error?
+5.3k PHP : Hide PHP version information from curl
+14.6k Golang : GUI with Qt and OpenCV to capture image from camera
+12.8k Swift : Convert (cast) Int or int32 value to CGFloat
+9.7k Golang : How to generate Code 39 barcode?
+11.1k Golang : Read until certain character to break for loop
+31.7k Golang : Get local IP and MAC address