c++qtappimage

AppImage/Qt6 - QIcon::setFallbackSearchPaths not working


I am trying to deploy a Qt6 application, which bundles its own icons (this way on Windows/OSX I get consistent icons). As part of my build I deploy into $BIN/share/icons the content of the breeze icons (I have a CMake function that does this for me).

In theory, I should do:

    QStringList paths;
    paths << QIcon::fallbackSearchPaths()
          << QDir(QCoreApplication::applicationDirPath() + "/../share/icons").absolutePath();
    qDebug() << "Icons search path" << paths;
    QIcon::setFallbackSearchPaths(paths);
    QIcon::setThemeName("Breeze");

and then in my code:

newFilePopup->setIcon(QIcon::fromTheme("document-new"));

This is not working for me. For some reasons, icons are not loaded.

My build structure looks OK ( in ../share/icons/ I have a subdir which has an icon index, and in my code I use it properly).

$ ~/src/program/build/ ls -l bin/program  share/icons/breeze/*.theme
-rwxrwxr-x 1 user user 12783136 Jul 25 18:42 bin/program
-rw-rw-r-- 1 user user    19288 Jul  5 13:52 share/icons/breeze/index.theme

I did not find documentation regarding this setup, and I don't see how to debug it. Internally the code uses QThemeIconEngine(name)) which is internal. Tried looking at the code - qt/qtbase/src/gui/image/qiconloader.cpp - but found no obvious way to debug.

EDIT: I am wondering if this is related to AppImage and platform integration.

When I run the application "normally" I can see the icons (even when I delete the system ones). However, when I package this as an AppImage - I don't see the icons.

I have modified the title as needed.


Solution

  • The problem I was facing, is that during the creation of the AppImage the icons plugin was not packed.

    I added these lines to my build script:

    mkdir -p "dist/${matrix_config_build_dir}/usr/plugins/iconengines/"
    mkdir -p "dist/${matrix_config_build_dir}/usr/plugins/platforms/"
    cp -arv $QTDIR/plugins/iconengines/* "dist/${matrix_config_build_dir}/usr/plugins/iconengines/"
    cp -arv $QTDIR/plugins/platforms/libqwayland-*.so "dist/${matrix_config_build_dir}/usr/plugins/platforms/"
    

    How did I discover this? I run ./program.AppImage --appimage-mount. This will display the mount point for my AppImage. Then I cd into it, and run from the top ./AppRun my application now runs, and I still see the problem (I could reproduce). Then I run strace -o 1.txt ./AppRun and evaluated the opened files. I saw that the program tries to open the iconengines directory - which was not available on the squashfs. This means that the Qt AppImage plugin is not copying it.

    That was not fun.