Important: Please read the Qt Code of Conduct -

[SOLVED] Notification when a QDialog gets closed

  • Hello,

    I have a class that has it's own UI, as well as several different further QDialogs. Like this:

    namespace Ui {
    class MyClass;

    void MyClass : public QDialog {


    /* yatta */

    QDialog *_buyingDialog;
    QDialog *_confirmDialog;

    /* yatta */



    Let's assume the following scenario: I want to interact with the object in several different ways. One of them results opening a dialog (for example, the buying dialog), which then in case leads to opening the confirm dialog. That means, at the time of the execution I have 2 dialogs open (at least): the interactive buying dialog, as well as the "do you really want to do that? y/n" dialog.

    What I want to do is: if the user closes (or hides!) the buying dialog (because he wants to, for whatever reason users do stuff they do :D), I want to get a notification to be able to also close the confirmDialog, if need be.

    I cannot override closeEvent in that case, because the dialog closed (/hidden) is not MyClass.
    In short: _buyingDialog gets closed or hidden by the user, I want to be notified to be able to hide _confirmDialog. Any signals or such I didn't see? Thanks for any help in advance!

  • Hi,
    Maybe overwrite the
    @ QWidget::hideEvent(QHideEvent * event) [virtual protected]@
    function in your buyingDialog and emit a signal there. Connect that signal to the minimize/close slot of the other dialog.

  • Hello Jeroen, thanks for the answer.

    _buyingDialog is a regular QDialog, not a derived class of QDialog. You're basically telling me I have to make a separate class to accomplish what I want? Or, respectively, alter QDialog alltogether?

    Or is there a way to override a method of a class from outside of the class for this one single instance of using an object from the class in c++ that I'm not aware of? I hope not, because this would break all concepts of encapsulation that my mind ever had. :D

  • Lifetime Qt Champion


    No you can't override a function from outside a class in c++. But what you can do in your case is to use an event filter. Have look at "this":

    Hope it helps

  • As I already wrote, "I hope not". Glad to see my view isn't being totally shattered.
    The Event Filter looks, from the glimpse I just took over it, perfect for my needs. Thank you!

Log in to reply