canardman
canardman

Reputation: 3263

Run QDialog object from a static function after QMainWindow is opened

I would like to open a modal dialog box (to log in) from a static function after the QMainWindow object is opened.

class DialogLog : public QDialog {
    DialogLog(QWidget * parent) : QDialog(parent) {
        //some code
        exec();
    }
};

class LogHandler {
    static bool log(QWidget * parent) {
        DialogLog dl(parent);
        //some code
    }
};

class WinMain : public QMainWindow {}

main(..) {
    QApplication app(..);

    WinMain fen;
    fen.show;

    app.exec();
};

EDIT : How can i run LogHandler::log() after/at the same time of WinMain ?

Upvotes: 1

Views: 500

Answers (1)

Jérôme
Jérôme

Reputation: 27027

There could be a better solution, but here is what you could do : use a singleshot timer that will shot immediatly (i.e. as soon as the event pump will be looping).

The timer will call a slot of, for instance, your WinMain class :

void main(..) {
    QApplication app(..);

    WinMain fen;
    fen.show;

    QTimer::singleShot(0, &fen, SLOT(login()));
    app.exec();
};

In the login() slot of WinMainyou would have your call to LogHandler::log() :

void WinMain::login() {
   if (!LogHandler::log(this))
      qApp->quit();
}

Upvotes: 2

Related Questions