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] How to detect QMainWindow destroy signal?
Forum Update on Monday, May 27th 2025

[Solved] How to detect QMainWindow destroy signal?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 10.4k Views
  • 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.
  • Z Offline
    Z Offline
    zither
    wrote on last edited by
    #1

    Dear all,

    @class myWin : public QMainWindow
    {
    Q_OBJECT
    myWin (QWidget *parent=0);
    ......
    ......
    }

    class Main : public QMainWindow
    {
    .......
    void Main::Function()
    {
    myWin *dialog = new myWin(this);
    dialog->show();
    connect(myWin,SIGNAL(destroyed()),this,SLOT(mySLOT())); //No signal is emitted after dialog is closed
    }
    ...
    }@

    Thanks

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      On what action do you want the dialog be "destroyed" clicking the x button in the titlebar?

      Maybe the signal "rejected":http://doc.qt.nokia.com/4.7/qdialog.html#rejected is what you want.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zither
        wrote on last edited by
        #3

        bq. On what action do you want the dialog be “destroyed” clicking the x button in the titlebar?Maybe the signal rejected [doc.qt.nokia.com] is what you want.

        Yes, clicking x button in the titlebar.

        But, I can't get rejected because myWin class in inheritance to QMainWindow. It occurs just as dialog but not QDialog class.

        @class myWin : public QMainWindow@

        How can I do that?

        Thanks

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          Ok, i see now it's a QMainwindow. If I were you I would name it differently like MyGoalMainwindow. Your code will be easier to read.

          Did you use a qDebug to see if your slot is called?

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zither
            wrote on last edited by
            #5

            Yes, I tested with qDebug(). NO call to mySlot.

            I also try with destroyed(QObject*))...

            How can I do that?

            Thanks

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              Hi zither,

              the point is that the main window will not be destroyed. destroyed will be emitted, if the object is deleted, not if the window is closed. I f you want the object really to be destroyed, then you can set the attribute:

              @
              myWin::myWin (QWidget *parent)
              ....
              {
              ....
              setAtrtribute(Qt::WA_DeleteOnClose, true);
              }
              @

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • EddyE Offline
                EddyE Offline
                Eddy
                wrote on last edited by
                #7

                try
                @myWin *dialog = new myWin(this);
                dialog->setAttribute(Qt::WA_DeleteOnClose, true);
                dialog->show(); @

                Edit : Gerolf is faster ;)

                Qt Certified Specialist
                www.edalsolutions.be

                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