PDA

View Full Version : How can i check if QMainWindow is fully loaded ?



umen
5th June 2011, 08:37
Hi
in my application i like to invoke method only after the window on the QMainWindow is fully loaded ,
how can i check this ? is there any onLoad callback/signal ? ( i checked and didn't found any thing )
Thanks

ChrisW67
5th June 2011, 08:53
What do you mean by "fully loaded"?

You can trigger some activity when the program returns to the Qt event loop with a single-shot timer at the end of the constructor:


#include <QtGui>
#include <QDebug>

class MainWindow: public QMainWindow {
Q_OBJECT
QLabel *label1;
QLabel *label2;
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
QWidget *central = new QWidget(this);
label1 = new QLabel("Label 1", this);
label2 = new QLabel("Label 2", this);

QVBoxLayout *layout = new QVBoxLayout(central);
layout->addWidget(label1);
layout->addWidget(label2);

central->setLayout(layout);
setCentralWidget(central);

QTimer::singleShot(0, this, SLOT(doLater()));
}
public slots:
void doLater() {
// Executes when event loop reached (after show in this case)
label2->setText("I've been changed");
}

private:
};

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"

nish
5th June 2011, 12:46
also try showEvent()

pkj
5th June 2011, 13:00
umen do you mean Form.OnLoad method ala .NET environment? No I think things run differently here. But if you want it that way you can definitely use signals and slots to come up with something similar in no time..:)