Qt如何从哪里找到closeEvent(QCloseEvent*事件)触发
Qt How to find out from where the closeEvent(QCloseEvent *event) fired
我的主窗口中有2个触发器1.从关闭应用程序的菜单中2.从忽略并隐藏窗口的窗口X按钮。我正在使用此SIGNAL/插槽我怎么能从哪里知道它被触发了?。
在closeEvent
:中
connect(ui->actionQuit, SIGNAL(triggered()),this, SLOT(CloseWin()));
void MainWindow::CloseWin()
{
close();
}
// triggered from the ui->actionQuit amd from the X button
void MainWindow::closeEvent(QCloseEvent *event)
{
// how can i know from where its bean triggered?
hide();
event->ignore();
}
通过调用QObject::sender()-http://developer.qt.nokia.com/doc/qt-4.8/qobject.html#sender。请注意,只有在对正在调用的SLOT调用此方法时,有效的返回值才可用。
编辑:
如果你将多个信号连接到一个插槽,你还应该考虑使用信号映射器,这在这个QQ中有解释:http://doc.qt.nokia.com/qq/qq10-signalmapper.html
有两种解决方案:
- 将菜单项(
QAction
)信号连接到一个单独的插槽,并在那里调用qApp->quit()
- 在插槽中使用
sender()
方法来确定发送信号的对象
我更喜欢第一个。
相关文章:
- Android NDK传感器向事件队列报告奇怪的间隔
- 从文本文件中读取时钟时间和事件时间并进行处理
- WMI检测进程创建事件-c++
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 处理闪烁窗口事件
- C++Builder中的OnClick事件签名存在问题
- 跟踪滚动条上的鼠标事件
- 什么是事件表 (wxWidgets)?
- 如何在 MFCaptureEngine 中获取"Camera removed"事件
- 给定顺序中的事件处理
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- 在 C++/CLI 中将 .NET 事件从一个 DLL 引发到另一个 DLL
- 如何创建事件驱动的 SDL2 应用程序
- Windows 进程间同步类似事件?
- 如何从C++端挂接到 QML 项的 onClick 事件
- 如何通过多类"Union variable" (sfml) 使用轮询事件
- 如何在Qt 4.8中阻止/忽略/丢弃早于特定超时的用户输入事件
- C++ 信号和插槽不工作:插槽不响应事件
- 在虚幻引擎中触发C++ dll的事件
- Qt如何从哪里找到closeEvent(QCloseEvent*事件)触发