@@ -76,7 +76,7 @@ inline bool createQtConf(appdir::AppDir &appDir) {
7676 return true ;
7777}
7878
79- inline bool createAppRunHook (appdir::AppDir &appDir) {
79+ inline bool createAppRunHook (appdir::AppDir &appDir, int qtMajorVersion ) {
8080 auto hookPath = appDir.path () / " apprun-hooks" / " linuxdeploy-plugin-qt-hook.sh" ;
8181
8282 try {
@@ -99,18 +99,25 @@ inline bool createAppRunHook(appdir::AppDir &appDir) {
9999 return false ;
100100 }
101101
102- // Old Qt versions only ship gtk2, new versions only gtk3. No Qt version had both.
103- const bool haveGtk3 = fs::exists (appDir.path () / " usr/plugins/platformthemes" / " libqgtk3.so" );
104-
105102 ofs << " # generated by linuxdeploy-plugin-qt" << std::endl
106103 << std::endl
107- << " # try to make Qt apps more \" native looking\" on Gtk-based desktops, if possible" << std::endl
108- << " # see https://github.com/AppImage/AppImageKit/issues/977#issue-462374883" << std::endl
109- << " case \" ${XDG_CURRENT_DESKTOP}\" in" << std::endl
110- << " *GNOME*|*gnome*|*XFCE*)" << std::endl
111- << " export QT_QPA_PLATFORMTHEME=" << (haveGtk3 ? " gtk3" : " gtk2" ) << std::endl
112- << " ;;" << std::endl
113- << " esac" << std::endl;
104+ << " # Override QT_PLUGIN_PATH to fall back to defaults. NixOS sets QT_PLUGIN_PATH," << std::endl
105+ << " # which causes AppImages with Qt to try and load system Qt plugins." << std::endl
106+ << " # This usually fails due to the mismatched Qt versions." << std::endl
107+ << " unset QT_PLUGIN_PATH" << std::endl;
108+
109+ if (qtMajorVersion >= 6 ) {
110+ // Old Qt versions only ship gtk2, new versions only gtk3. No Qt version had both.
111+ const bool haveGtk3 = fs::exists (appDir.path () / " usr/plugins/platformthemes" / " libqgtk3.so" );
112+ ofs << std::endl
113+ << " # try to make Qt apps more \" native looking\" on Gtk-based desktops, if possible" << std::endl
114+ << " # see https://github.com/AppImage/AppImageKit/issues/977#issue-462374883" << std::endl
115+ << " case \" ${XDG_CURRENT_DESKTOP}\" in" << std::endl
116+ << " *GNOME*|*gnome*|*XFCE*)" << std::endl
117+ << " export QT_QPA_PLATFORMTHEME=" << (haveGtk3 ? " gtk3" : " gtk2" ) << std::endl
118+ << " ;;" << std::endl
119+ << " esac" << std::endl;
120+ }
114121
115122 return true ;
116123}
0 commit comments