Show messageBox when click exit button on titlebar.
-
I want to show a MessageBox when User click to exit button on title bar for close application In my qdalog.
When user click exit button messagebox should ask about quit and if user click yes, I will close my serial port and close Qdialog. How can I do this?
-
@mangekoyu
You might want to close serial port from QCoreApplication::aboutToQuit(). But you can't show a dialog or ask from there.For the dialog you need to subclass
QMainWindow
(you should already be doing that) and overridecloseEvent
. There you can show a dialog and only accept the close event if the user confirms. See e.g. show a dialog before closing the program in Qt. -
void productDetail::closeEvent1(QCloseEvent *event) // show prompt when user wants to close app { event->ignore(); if (QMessageBox::Yes == QMessageBox::question(this, "Close Confirmation", "Exit?", QMessageBox::Yes | QMessageBox::No)) { event->accept(); } }
I tried sth like this but message box does not shown.
-
@mangekoyu do you know how overriding works ?
productDetail::closeEvent1(QCloseEvent *event)
the base function most certainly does not have a1
at the end of the function name. -
@mangekoyu said in Show messageBox when click exit button on titlebar.:
void productDetail::closeEvent1()
Did the example put a
1
at the end ofcloseEvent
? You cannot just type in something different from what an example shows and then say why does it not work.....I tried sth like this
People can't help much if you say you have code "something like", how can we know what you actually have?
Please think about phrasing questions and giving detail/proper code, people cannot guess what you might be doing. It will help you and help us.