首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用windeployqt工具后QSystemTrayIcon未显示

使用windeployqt工具后QSystemTrayIcon未显示
EN

Stack Overflow用户
提问于 2019-09-13 14:06:59
回答 1查看 145关注 0票数 0

注意:是的,这个问题以前已经问过并回答过了,但是重复的答案是不完整的。如果你被困在这上面,请看我的解决方案。

使用QT5.13.0 MSVC2017 64位和Windows 10,我正在经历一些来自QSystemTrayIcon的奇怪行为。当在新版本上运行Debug或从QtCreator发布时,没有问题,图标显示了我期望的结果。但是,在使用windeployqt.exe工具后,图标将停止显示。

当我在QtCreator运行windeployqt.exe后和通过QtCreator从安装目录运行它时,都会发生这种情况。如果我删除构建目录、清理和重建,问题就会消失,但显然这是部署的一个问题。

命令:

代码语言:javascript
复制
windeployqt.exe <RELEASE_DIR>

(还尝试直接指定可执行文件)

MainWindow构造函数:

代码语言:javascript
复制
AltheaWindow::AltheaWindow(MacroListModel &macroListModel, 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(&macroListModel);
    if ((*(*config)[AltheaConfig::StartMinimized]).toBool()) showMinimized();
}

无论图标是否显示,exists始终是true,因此它似乎不是解决资源的问题。应用程序中的所有其他资源也可以正常工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-13 19:16:01

找到解决方案后,将图像格式复制到插件目录。

解决方案:https://stackoverflow.com/a/20594583/2472874

附加注意:对于任何遇到这个问题的人,我发现在初始化应用程序对象之前,我还需要在Library路径上安装图像格式插件。

代码语言:javascript
复制
#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));
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57925193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档