Qt 中的系统托盘图标在调试模式下工作但不在发布模式下工作 [英] System tray icon working in debug but not release mode, in Qt
问题描述
我有一个 Qt 应用程序,带有系统托盘图标和右键单击该图标时显示的菜单.出于某种原因,菜单项在调试模式下工作正常,但在发布模式下无效.
I have a Qt application with a system tray icon and a menu that shows up when right-clicking the icon. For some reason, the menu items work fine in debug mode but not in release mode.
QAction* closeAction = new QAction("Close", this);
QMenu* trayIconMenu = new QMenu(this);
trayIconMenu->addAction(closeAction);
QSystemTrayIcon* trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
QIcon trayIconIcon("Application.png");
trayIcon->setIcon(trayIconIcon);
trayIcon->show();
QObject::connect(closeAction, SIGNAL(triggered()), this, SLOT(trayIconCloseAction_triggered()));
void MainWindow::trayIconCloseAction_triggered() {
MessageBoxes::info("Close item clicked");
}
当我右键单击图标时,菜单会显示出来,但单击关闭"什么也不做 - trayIconCloseAction_triggered()
根本没有被调用.它仅在发布模式下执行此操作.有人知道可能是什么原因吗?
When I right-click on the icon, the menu shows up but clicking on "Close" does nothing - trayIconCloseAction_triggered()
is not called at all. It does this only in release mode. Does anybody know what could be the reason?
我使用的是 Windows 7 和 Qt Creator,使用 Qt 的 MSV-2010 静态版本进行构建.
I am using Windows 7 and Qt Creator, building with an MSV-2010 static build of Qt.
该图标也不会对点击事件(激活"信号)做出反应.再次在调试模式下它可以工作,但不能发布.
The icon does not react to click events ("activated" signals) either. Again in debug mode it works, but not release.
推荐答案
在这种情况下,一般建议:
In situations like this there is a general recommendation:
- 删除构建目录中的release"和debug"文件夹,
- 使用 Qt creator 中build"菜单中的clean all"操作,
- 切换到发布模式,然后使用Run qmake"、rebuild all"操作,
- 按 Ctrl+R 并检查所需的功能.
这篇关于Qt 中的系统托盘图标在调试模式下工作但不在发布模式下工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!