How to run a class method after its constructor (Qt GUI)?

A QMainwindow object is created and displayed () n in the main () function of the program. This object constructor is used to create all GUI widgets. It contains additional code (or a method call) that is currently being executed before the QMainWindow widget appears.

This code / method should be run once after the QMainWindow constructor, that is, when the application window is visible.

According to the showEvent documentation, you can run it more than once.

Do I need to use any switch flag inside this event, or is there a "better" solution (I thought I read that QTimer can be used to set event loop cycle methods)?

+4
source share
1 answer

You can try using the Qt one-time timer with a timeout of 0 seconds. Call this at the end of your mainwindow constructor, connecting your callback function as a slot. QTimer :: singleShot (0, this, SLOT (onLoad ());

+4
source

All Articles