SetModal() does not work in QDialog
-
For some reason the setModal method is not working for me. Below is a snippet of code that calls a QDialog.
@QHash<QString, QVariant>* DataAccess::getSettings() // Private method
{
QHash<QString, QVariant> *parameters = new QHash<QString, QVariant>();Configconnec *confconnec; /GUI for get parameters of connection/
QSettings connecsettings( QSettings::IniFormat, QSettings::SystemScope, "Freedom", "TecTracker");
connecsettings.beginGroup("Connection");
if(!connecsettings.contains("host")) /*If connection settings not existis*/ { confconnec = new Configconnec(); confconnec->exec(true); /*Get new connection settings*/ } parameters->insert("host", connecsettings.value("host", "127.0.0.1")); parameters->insert("port", connecsettings.value("port", 5432)); parameters->insert("database", connecsettings.value("database", "postgres")); parameters->insert("user", connecsettings.value("user", "postgres")); parameters->insert("passw", connecsettings.value("passw", "postgres"));
connecsettings.endGroup();
if(confconnec)
delete confconnec;return parameters;
}@exec() method of Confconnec
@QDialog* Configconnec::exec(bool modal) // Show connection form
{
diagconnec->setModal(modal);
diagconnec->show();
return diagconnec;
}@If diagconnec is not modal, the program don't stop in line:
@ if(!connecsettings.contains("host")) /If connection settings not existis/
{
confconnec = new Configconnec();
confconnec->exec(true); /DON'T STOP HERE/
}
@He leaves the IF and step through the code, and I do not want it. He should expect the user closes the Dialog to proceed.
I get the desired effect by calling the exec(), but with setModal() and show() does not work. -
Hi,
There's no reason for your dialog to stop your application there. In your custom exec you are calling show which purpose is exactly to show your dialog without blocking the event loop.
-
Strange, the "documentation":http://qt-project.org/doc/qt-5/qdialog.html#modal-prop says that if we define the modal property to true, the show() loads widget as modal. And I'm setting to true before calling show()
-
AFAIK, modal doesn't mean "blocking your application's event loop", it means that you are blocking the access to the widgets underneath. If you want to block your application's flow, call the original exec()
-
ok!
exec() is the only option or is there some property that can be set?
-
It's the only option, however take also a look at open, it's also not blocking but proposes an alternative architecture that's worth to think about.