Qt如何等待/知道QMainWindow被关闭?

3

我怎样才能知道QMainWindow何时关闭?这样我就可以更新另一个窗口中的列表...

最好能够等到它关闭。

account.h:

class account : public QMainWindow
{
//...

accounts.h

class accounts : public QMainWindow
{
//...
public:
   account accWin;
//...

accounts.cpp

//...
void accounts::on_myAction()
{
   accWin.show();
   //how do I wait/know here for accWin to be closed ? (accWin is modal)
}
1个回答

5
你可以重载QWidget::closeEvent(QCloseEvent*)函数,在你的QMainWindow中进行列表更新。当窗口接收到关闭请求时(close request),closeEvent函数将被调用(即在窗口仍可见时)。
另外,你也可以连接到窗口的QObject::destroyed(QObject*)信号。

似乎我缺少一些面向对象编程的知识...你说的覆盖closeEvent是什么意思?哪一个? - sdadffdfd
谢谢,它应该可以工作...但我刚刚发现了信号和槽,它看起来非常简单并且对我很有用...我开始讨厌Qt了 :/ - sdadffdfd

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接