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 i开发者_运维问答n the middle blocking the main windows until ok button is presetUse 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();
}
精彩评论