Qt 和 Visual Studio。托盘图标消失
Qt and Visual Studio. Tray icon disappearance
我在 Visual Studio 中使用 Qt,我需要在应用程序中设置托盘图标。
我使用下一个代码:
QSystemTrayIcon trayIcon = new QSystemTrayIcon(this);
QIcon trayImage(":/Res/myIcon.ico");
trayIcon->setIcon(trayImage);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->show();
我的qrc文件:
<RCC>
<qresource prefix="/">
<file>Res/myIcon.ico</file>
</qresource>
</RCC>
它奏效了。但是,当我将我的应用程序移动到另一台计算机时,它因错误 "This application failed to start because it could not find or load the Qt platform plugin 'windows'." 而失败。我通过在包含执行文件的目录中创建目录 "platforms" 并将 qwindows.dll 放入其中来解决它。但在那之后图标消失了。我在托盘中只看到空白方块。我可以使用托盘图标操作,但我的图像不显示。
谢谢你知道为什么会这样。
我看了description of QIcon
class, where you can find link to supported formats QImageReader::supportedImageFormats()
,没有.ico
格式。
我不确定,但它可能是您问题的根源。尝试将图标格式更改为另一种格式。
将Qt 应用程序部署到其他机器时,您还需要为所需的图像格式部署插件。在您的情况下,您必须创建 imageformats
目录并复制 qico.dll
插件(可以在 Qt SDK 目录中找到)。
尽管如此,鉴于其更好的便携性,我建议您使用 PNG 格式作为托盘图标。
你应该使用 qt 支持的图像格式之一。例如,如果您使用 .png 格式,它将显示。
我在 Visual Studio 中使用 Qt,我需要在应用程序中设置托盘图标。 我使用下一个代码:
QSystemTrayIcon trayIcon = new QSystemTrayIcon(this);
QIcon trayImage(":/Res/myIcon.ico");
trayIcon->setIcon(trayImage);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->show();
我的qrc文件:
<RCC>
<qresource prefix="/">
<file>Res/myIcon.ico</file>
</qresource>
</RCC>
它奏效了。但是,当我将我的应用程序移动到另一台计算机时,它因错误 "This application failed to start because it could not find or load the Qt platform plugin 'windows'." 而失败。我通过在包含执行文件的目录中创建目录 "platforms" 并将 qwindows.dll 放入其中来解决它。但在那之后图标消失了。我在托盘中只看到空白方块。我可以使用托盘图标操作,但我的图像不显示。
谢谢你知道为什么会这样。
我看了description of QIcon
class, where you can find link to supported formats QImageReader::supportedImageFormats()
,没有.ico
格式。
我不确定,但它可能是您问题的根源。尝试将图标格式更改为另一种格式。
将Qt 应用程序部署到其他机器时,您还需要为所需的图像格式部署插件。在您的情况下,您必须创建 imageformats
目录并复制 qico.dll
插件(可以在 Qt SDK 目录中找到)。
尽管如此,鉴于其更好的便携性,我建议您使用 PNG 格式作为托盘图标。
你应该使用 qt 支持的图像格式之一。例如,如果您使用 .png 格式,它将显示。