【问题标题】:QSystemTrayIcon not showing after using windeployqt tool [duplicate]使用windeployqt工具后QSystemTrayIcon不显示[重复]
【发布时间】:2019-09-13 14:06:59
【问题描述】:

注意:是的,这个问题之前已经提出并回答过,但重复的回答不完整。如果您遇到此问题,请查看我的解决方案。

使用 Qt 5.13.0 MSVC2017 64 位和 Windows 10,我遇到了来自 QSystemTrayIcon 的一些奇怪行为。在全新构建的 QtCreator 中运行调试或发布时,没有任何问题,并且图标完全按照我的预期显示。但是,使用windeployqt.exe 工具后,图标不再显示。

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

命令:

windeployqt.exe <RELEASE_DIR>

(也试过直接指定可执行文件)

MainWindow 构造函数:

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,所以似乎不是解决资源的问题。应用程序中的所有其他资源也可以正常工作。

【问题讨论】:

  • IconPath 长什么样子?有时,托盘图标是隐藏的 - 您必须使用 Windows 设置在任务栏上明确显示它。
  • const QString AltheaWindow::IconPath = ":/icons/althea.ico";
  • 您能否通过在 Windows 设置中明确显示来详细说明您的意思?
  • 在任务栏右侧,您希望看到托盘图标的位置,有一个小箭头按钮^。它的工具提示说“显示隐藏的图标”。当您单击它时,会出现一个带有一些附加图标的弹出窗口。你的偶像在其中吗?
  • 哦,我明白你的意思了,默认情况下所有图标对我来说都是隐藏的,不,它不在那里。在我使用 windeployqt 之前它就在那里。

标签: c++ windows qt


【解决方案1】:

找到解决办法,把imageformats复制到plugins目录下。

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

补充说明: 对于遇到此问题的任何人,我发现我还需要在库路径上安装 imageformats 插件之前应用程序对象被初始化。

#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));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多