A QMainwindow object is constructed and show()n in the program's main() function. This object's constructur is used to create all GUI widgets. It contains additional code (or a method call) that is currently run before the QMainWindow widget is visible.
This code / method should be run once after the QMainWindow constructor, i.e. when the application window is visible.
According the the documentation of showEvent, it may be run more than once.
Do I need to use some sort of toggle flag inside this event, or is there a "better" solution (I thought I read that a QTimer could be used to enqueue methods to the event loop)?
You can try using a Qt singleshot timer with timeout of 0 seconds. Call this at the end of your mainwindow constructor connecting your callback function as the slot:
QTimer::singleShot( 0, this, SLOT( onLoad() ) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With