Call the mdiSubWindow destroyed slot from inside its class
Unsolved
General and Desktop
-
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? -
Hi,
What do you mean by
not implemented
? Isn'tPSubWindow::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.