gpt4 book ai didi

c++ - 如何在退出时调用插槽

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:24:03 26 4
gpt4 key购买 nike

我想在我的 Qt 应用程序关闭之前更新我的数据库。

我想要类似connect(this, SIGNAL(quit()), this, SLOT(updateDatabase()))一种方法是引入一个退出按钮,但是如果用户按下 Alt+F4 是否可以实现此功能?

最佳答案

使用信号aboutToQuit()相反。

This signal is emitted when the application is about to quit the main event loop, e.g. when the event loop level drops to zero. This may happen either after a call to quit() from inside the application or when the users shuts down the entire desktop session.

The signal is particularly useful if your application has to do some last-second cleanup. Note that no user interaction is possible in this state.

例如:

connect(this, SIGNAL(aboutToQuit()), this, SLOT(updateDatabase()));

关于c++ - 如何在退出时调用插槽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15731638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com