user63898
user63898

Reputation: 30973

Qt How to open QDialog when main application done fully to load all widgets

Hello all I have main windows application and I like to popup dialog for settings when the application (the qMainWindow)
Is fully loaded ? I tried to just in the main window constructor:

SettingsDialog settingsDialog;
settingsDialog.exec();

but when I start my application I see the QDialog and the main window minimized in the background
what I need that my main windows will be in the background but not minimized and the QDialog in the middle blocking the main windows until ok button is preset

Upvotes: 2

Views: 7912

Answers (1)

Begemoth
Begemoth

Reputation: 1389

Use QTimer::singleShot with zero time interval it will call specified slot from the event loop when constructor and show() have been completed. Here is an example:

#include <QtCore/QTimer>
#include <QtGui/QApplication>
#include <QtGui/QDialog>
#include <QtGui/QMainWindow>

class MW : public QMainWindow
{
  Q_OBJECT
public:
  MW();
private slots:
  void showDialog();
};

MW::MW()
{
  QTimer::singleShot(0, this, SLOT(showDialog()));
}

void MW::showDialog()
{
  QDialog d;
  d.setWindowTitle("dialog");
  d.exec();
}

int main(int argc, char* argv[])
{
  QApplication app(argc, argv);
  MW mw;
  mw.show();
  app.exec();
}

Upvotes: 4

Related Questions