Reputation: 3032
I need to start a job when QMainWindow
and all its widgets are initialized and rendered.
How can I catch such event?
Upvotes: 2
Views: 1580
Reputation: 4286
I see two ways of doing this.
Sophisticated:
void MainWindow::showEvent(QShowEvent *e)
{
QMainWindow::showEvent(e);
static bool firstStart = true;
if (firstStart)
{
emit startJob();
firstStart = false;
}
}
And easy one (suitable only, if you show main window right after creating):
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
...
QTimer::singleShot(500, this, SLOT(job()));
}
Update:
Like Chris
said, showEvent
is much more appropriate here, than paintEvent
.
Upvotes: 4