QDialog exec no longer modal after show
-
Show() creates a modeless dialog. So don't use it when you want a modal one.
-
wrote on 8 Sept 2023, 17:57 last edited by
@SGaist said in QDialog exec no longer modal after show:
Hi,
Are you explicitly setting the modality of your dialog ?
No. setModal(true) doesn't fix the problem though.
-
Show() creates a modeless dialog. So don't use it when you want a modal one.
wrote on 8 Sept 2023, 17:57 last edited by@Christian-Ehrlicher said in QDialog exec no longer modal after show:
Show() creates a modeless dialog. So don't use it when you want a modal one.
Uh uh, did you read why it's needed?
-
@Christian-Ehrlicher said in QDialog exec no longer modal after show:
Show() creates a modeless dialog. So don't use it when you want a modal one.
Uh uh, did you read why it's needed?
@SamiV123 Yes. Maybe you can convince the devs to change this behavior but I doubt it.
http://bugreports.qt.io -
Did you experiment with open as well ?
-
wrote on 8 Sept 2023, 19:16 last edited by
@SGaist said in QDialog exec no longer modal after show:
Did you experiment with open as well ?
I did, but I don't know what's going on with open(). the whole dialog just disappeared and was not visible. Weird.
-
@SGaist said in QDialog exec no longer modal after show:
Did you experiment with open as well ?
I did, but I don't know what's going on with open(). the whole dialog just disappeared and was not visible. Weird.
Check your dialog lifetime. If it's a function local object then it will be destroyed after calling open since it's the last method call in the function.
-
@SGaist said in QDialog exec no longer modal after show:
Did you experiment with open as well ?
I did, but I don't know what's going on with open(). the whole dialog just disappeared and was not visible. Weird.
wrote on 8 Sept 2023, 20:49 last edited by@SamiV123
try this:class DlgMsg : public QDialog { public: DlgMsg() : QDialog(nullptr) {} void showMessage(const QString& str) { QTimer::singleShot(1000,this,[str,this]() { auto msg=QMessageBox(this); msg.setWindowModality(Qt::WindowModal); msg.setText(str); msg.exec(); }); } }; ... DlgMsg dmsg; dmsg.resize(400,200); dmsg.showMessage("Something wrong happened!"); dmsg.exec();
-
Check your dialog lifetime. If it's a function local object then it will be destroyed after calling open since it's the last method call in the function.
wrote on 9 Sept 2023, 09:01 last edited by@SGaist said in QDialog exec no longer modal after show:
Check your dialog lifetime. If it's a function local object then it will be destroyed after calling open since it's the last method call in the function.
Doh, you're right, so open() returns immediately so of course that will that not work.
Actually open() seems very cumbersome to use, it's a lot easier to simply create the Dialog on the stack and call exec()
-
@SGaist said in QDialog exec no longer modal after show:
Check your dialog lifetime. If it's a function local object then it will be destroyed after calling open since it's the last method call in the function.
Doh, you're right, so open() returns immediately so of course that will that not work.
Actually open() seems very cumbersome to use, it's a lot easier to simply create the Dialog on the stack and call exec()
As explained in the method documentation, exec has some caveats to take into account when you design your application.
12/12