Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Notification when a QDialog gets closed
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Notification when a QDialog gets closed

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aerius
    wrote on last edited by
    #1

    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 {

    Q_OBJECT
    

    public:
    /* yatta */

    private:
    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!

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      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.
      Greetz

      Greetz, Jeroen

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Aerius
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          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":http://qt-project.org/doc/qt-4.8/qobject.html#installEventFilter

          Hope it helps

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Aerius
            wrote on last edited by
            #5

            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!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved