PDA

View Full Version : QMainWindow: create onStartup-like function [SOLVED]



thomaspu
11th October 2012, 14:09
My application has a QMainWindow and I need to run one of its functions after the QApplicaiton event engine is running. Any suggestions?


#include <QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWin;
mainWin.show();
return app.exec(); //Right after this, event engine is running. How to send something to my mainWin to run my onStarup()? signal? event??
}

//MainWin...
MainWindow::MainWindow() {}
MainWindow::onStartup() {} //Call this, display a QProgressBar and do some stuff

wysota
11th October 2012, 14:12
Use QMetaObject::invokeMethod() with Qt::QueuedConnection.

Lesiok
11th October 2012, 14:14
In MainWindow declare onStartup as a slot and in constructor use something like this :

QTimer::singleShot(0,this,SLOT(onStartup());

thomaspu
11th October 2012, 14:42
Cool, thats just what I was looking for.

Paul