I have subclassed QDialog
and I have created a const
method, because I want to definitely prevent modifications of my instance. Now if a certain error occurs, I would like to use a QMessageBox
to display it. But I can't use this
as the parent of the message box, because this
is const
.
This is a pity. According to the documentation (https://doc.qt.io/qt-5/qdialog.html#QDialog) the parent influences the default location of the new dialog and whether it shares the parent's taskbar entry. Does the parent necessarily have to be non-const
for that...?
I see three options, none of them being obviously excellent:
const_cast
(seems strange to me to useconst_cast
in such a common situation)- use
nullptr
as parent (ugly, because the message box position is worse) - make my method non-const (ugly, because the compiler would not anymore support me in protecting the instance)
Is Qt not const-correct when it demands the parent widget to be modifiable? And is there a better solution than the const_cast
?