Skip to content

Commit 7bb3f05

Browse files
committed
Unset QT_PLUGIN_PATH. This avoids Qt version mismatches when QT_PLUGIN_PATH is set on the host. This is often the case on NixOS.
1 parent d15373b commit 7bb3f05

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/deployment.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/main.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,10 @@ int main(const int argc, const char *const *const argv) {
308308
return 1;
309309
}
310310

311-
if (qtMajorVersion >= 6) {
312-
ldLog() << std::endl << "-- Note: skipping AppRun hook creation on Qt " << qtMajorVersion << " --" << std::endl;
313-
} else {
314-
ldLog() << std::endl << "-- Creating AppRun hook --" << std::endl;
315-
if (!createAppRunHook(appDir)) {
316-
ldLog() << LD_ERROR << "Failed to create AppRun hook in AppDir" << std::endl;
317-
return 1;
318-
}
311+
ldLog() << std::endl << "-- Creating AppRun hook --" << std::endl;
312+
if (!createAppRunHook(appDir, qtMajorVersion)) {
313+
ldLog() << LD_ERROR << "Failed to create AppRun hook in AppDir" << std::endl;
314+
return 1;
319315
}
320316

321317
ldLog() << std::endl << "Done!" << std::endl;

0 commit comments

Comments
 (0)