Solved Modal QDialog without exec()?
-
The
QDialog::exec()
doc says: "Avoid using this function; instead, useopen().
"Does this mean: avoid modal dialogs for good, always use modeless dialogs?
Or is there recommended way to run a modal dialog starting with
open()
? -
@Joachim-W
See https://doc.qt.io/qt-5/qdialog.html#modal-prop.You can make the dialog be modal with this when it
open()
s.exec()
does that automatically (regardless ofsetModal()
), but also sits there waiting, whereasopen()
with modal does the modality but does not spin the wait loop (but you can act on signal https://doc.qt.io/qt-5/qdialog.html#finished).So long as you don't do anything "naughty", I like a lot of people find it fine to use
exec()
for the default, normal cases. Purists may adviseopen()
, butexec()
works fine for me.