[Solved] How to detect QMainWindow destroy signal?
-
wrote on 14 Aug 2011, 03:03 last edited by
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
-
wrote on 14 Aug 2011, 03:18 last edited by
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.
-
wrote on 14 Aug 2011, 03:26 last edited by
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
-
wrote on 14 Aug 2011, 03:42 last edited by
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?
-
wrote on 14 Aug 2011, 03:56 last edited by
Yes, I tested with qDebug(). NO call to mySlot.
I also try with destroyed(QObject*))...
How can I do that?
Thanks
-
wrote on 14 Aug 2011, 05:25 last edited by
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);
}
@ -
wrote on 14 Aug 2011, 05:38 last edited by
try
@myWin *dialog = new myWin(this);
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
dialog->show(); @Edit : Gerolf is faster ;)
1/7