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. Call the mdiSubWindow destroyed slot from inside its class

Call the mdiSubWindow destroyed slot from inside its class

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 623 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.
  • P Offline
    P Offline
    Prmego
    wrote on last edited by
    #1

    I have an override QMdiSubWindow class as follow:

    // Declaration
    class PSubWindow : public QMdiSubWindow {
        Q_OBJECT
    
    public:
        explicit PSubWindow(QMdiArea *parent = 0);
        ~PSubWindow();
    private:
        QMdiArea *parent;
    protected:
        void closeEvent(QCloseEvent *event);
    protected slots:
        void on_subWindow_destroyed(QObject *window);
    };
    
    // Definition (Constructor)
    PSubWindow::PSubWindow(QMdiArea *parent) : QMdiSubWindow(parent){
        this->parent = parent;
        static ushort counter = 1;
        this->setAttribute(Qt::WA_DeleteOnClose);
        this->setObjectName("subWindow" + QString::number(counter));
        this->setWindowTitle("Untitled " + QString::number(counter++));
        // this is the target connection.
        QObject::connect(this, SIGNAL(destroyed(QObject*)), this, SLOT(on_subWindow_destroyed(QObject*)));
    }
    void PSubWindow::on_subWindow_destroyed(QObject *window) {
        qDebug()<< "sub-window destroyed";
    }
    void PSubWindow::closeEvent(QCloseEvent *event) {
        //qDebug()<< "closeEvent";
    }
    

    And then, I have created an instance of subWindow in another class as follow:

    QMdiSubWindow *PActions::newFile() {
        PSubWindow *newWindow = new PSubWindow(this->mdiareaContainer);
        QMdiSubWindow *subWindow = mdiareaContainer->addSubWindow(newWindow);
        newWindow->show();
        return subWindow;
    }
    

    The problem is the destroyed connection is not implemented, and it does not report any error.
    is there anything wrong in my code?

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

      Hi,

      What do you mean by not implemented ? Isn't PSubWindow::on_subWindow_destroyed the implementation of that method ?

      On a side note, connecting the destroyed signal from a class to an method of the same class isn't exactly a good idea. You are basically trying to call a method from an object that has been destroyed.

      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
      1

      • Login

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