注意:是的,这个问题以前已经问过并回答过了,但是重复的答案是不完整的。如果你被困在这上面,请看我的解决方案。。
使用QT5.13.0 MSVC2017 64位和Windows 10,我正在经历一些来自QSystemTrayIcon的奇怪行为。当在新版本上运行Debug或从QtCreator发布时,没有问题,图标显示了我期望的结果。但是,在使用windeployqt.exe工具后,图标将停止显示。
当我在QtCreator运行windeployqt.exe后和通过QtCreator从安装目录运行它时,都会发生这种情况。如果我删除构建目录、清理和重建,问题就会消失,但显然这是部署的一个问题。
命令:
windeployqt.exe <RELEASE_DIR>(还尝试直接指定可执行文件)
MainWindow构造函数:
AltheaWindow::AltheaWindow(MacroListModel ¯oListModel, Config *config, const QString &configPath, QWidget *parent)
: QMainWindow(parent),
ui(new Ui::AltheaWindow),
macros(macroListModel),
config(config),
trayIcon(QIcon(IconPath), this),
shortcutNew(ShortcutPtr(new QShortcut(NewMacro, this))),
shortcutSave(ShortcutPtr(new QShortcut(SaveMacro, this))) {
qDebug() << "AltheaWindow";
ui->setupUi(this);
ui->sidebar->createSettingsDialog(config, configPath);
initConnections();
QFile f(IconPath);
bool exists = f.exists();
qDebug() << "exists = " << exists; // "exists = true"
trayIcon.show();
ui->sidebar->setMacros(¯oListModel);
if ((*(*config)[AltheaConfig::StartMinimized]).toBool()) showMinimized();
}无论图标是否显示,exists始终是true,因此它似乎不是解决资源的问题。应用程序中的所有其他资源也可以正常工作。
发布于 2019-09-13 19:16:01
找到解决方案后,将图像格式复制到插件目录。
解决方案:https://stackoverflow.com/a/20594583/2472874
附加注意:对于任何遇到这个问题的人,我发现在初始化应用程序对象之前,我还需要在Library路径上安装图像格式插件。
#define PLUGINS "plugins"
void preInit(char *argv[]);
int main(int argc, char *argv[]) {
#ifndef _DEBUG
preInit(argv);
#endif
Althea app(argc, argv);
AltheaWindow w(app.getMacros(), &app.getConfig(), app.getAppData().absoluteFilePath(Althea::ConfigFileName));
w.show();
return app.exec();
}
void preInit(char *argv[]) {
QDir releaseDir(QFileInfo(argv[0]).dir());
QCoreApplication::addLibraryPath(releaseDir.absoluteFilePath(PLUGINS));
}https://stackoverflow.com/questions/57925193
复制相似问题