Qt

From NixOS Wiki
Revision as of 13:59, 29 October 2018 by imported>Das-g (→‎qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in "": add filename & programming language for example shell.nix (for workaround))

Troubleshooting

Cannot mix incompatible Qt library (version 0x_____) with this library (version 0x_____)

This is a known issue, see #30551 for the current status.

This application failed to start because it could not find or load the Qt platform plugin ??? in ""

qt4

Qt4 depends on the environment variable QT_PLUGIN_PATH to find plugins. It is normally already

present in the environment on NixOS at least, but for example systemd user units are launched in a pretty empty environment. A solution is to use the command

systemctl --user import-environment QT_PLUGIN_PATH

from a sane environment. For example add it to the services.xserver.displayManager.sessionCommands option.

qt5

Qt5 seems (?) to look for plugins in the PATH. This will fail from a systemd user unit for example, because their path is nearly empty by default. As an example, here is a workaround to have usbguard-applet launched from a systemd user unit:

/etc/nixos/configuration.nix
  systemd.user.services.usbguard-applet = {
    description = "USBGuard applet";
    partOf = [ "graphical-session.target" ];
    wantedBy = [ "graphical-session.target" ];
    path = [ "/run/current-system/sw/" ]; ### Fix empty PATH to find qt plugins
    serviceConfig = {
      ExecStart = "${pkgs.usbguard}/bin/usbguard-applet-qt";
    };
  };

qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""

Here is a concrete example:

qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

One solution is to run a command like

env QT_PLUGIN_PATH=/nix/store/d7q3q6wmfccss8gcp09r33xg0wkbz9gb-qtbase-5.11.0-bin/lib/qt-5.11/plugins/ some_qt_app

Another is to set the variable in a shell.nix file like the following

shell.nix
with import <nixpkgs> {};

stdenv.mkDerivation {
  name = "qt-somethingorother";

  buildInputs = [
    pkgs.somePackage
    ];
  QT_PLUGIN_PATH = qt5.qtbase.bin + "/" + qt5.qtbase.qtPluginPrefix;
  }

to be run with

nix-shell shell.nix

Debugging methods

As a general rule, exporting QT_DEBUG_PLUGINS=1 make qt print where it looks for plugins.

If a plugin exists in a directory but is ignored with a message like QLibraryPrivate::loadPlugin failed on "/nix/store/...-teamspeak-client-3.1.6/lib/teamspeak/platforms/libqxcb.so" : "Cannot load library /nix/store/...-client-3.1.6/lib/teamspeak/platforms/libqxcb.so: " it can be that the library cannot be dlopen()ed because of dependencies/rpath issues and needs patchelfing. Exporting LD_DEBUG=libs may prove helpful in this scenario.