[Solved] How to detect QMainWindow destroy signal?
-
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
-
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.
-
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
-
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?
-
Yes, I tested with qDebug(). NO call to mySlot.
I also try with destroyed(QObject*))...
How can I do that?
Thanks
-
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);
}
@ -
try
@myWin *dialog = new myWin(this);
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
dialog->show(); @Edit : Gerolf is faster ;)