Qt: Difference between revisions
imported>Samueldr m Adds link to the fix... keep this until 20.03 for stragglers on 19.03 and before→Cannot mix incompatible Qt library (version 0x_____) with this library (version 0x_____) |
imported>Makefu No edit summary |
||
Line 10: | Line 10: | ||
For using direnv, create a '''shell.nix''' file in the root of your project and paste these lines into it: | For using direnv, create a '''shell.nix''' file in the root of your project and paste these lines into it: | ||
<syntaxHighlight lang=nix> | |||
# shell.nix | |||
{ pkgs ? import <nixpkgs> {} }: | { pkgs ? import <nixpkgs> {} }: | ||
pkgs.mkShell { | pkgs.mkShell { | ||
Line 19: | Line 19: | ||
]; | ]; | ||
} | } | ||
</ | </syntaxHighlight> | ||
Tip: if you want use clang-format, add '''clang-format''' to '''buildinputs''' list. | Tip: if you want use clang-format, add '''clang-format''' to '''buildinputs''' list. | ||
Line 64: | Line 64: | ||
</pre> | </pre> | ||
The package will need to be fixed to use [the new https://github.com/NixOS/nixpkgs/issues/65399 <code>wrapQtAppsHook</code>]. | The package will need to be fixed to use [the new https://github.com/NixOS/nixpkgs/issues/65399 <code>wrapQtAppsHook</code>]. The hook wraps every qt application with adding <code>QT_PLUGIN_PATH</code> and <code>XDG_DATA_DIRS</code> as well as <code>XDG_CONFIG_DIRS</code>.See [https://github.com/NixOS/nixpkgs/blob/nixos-19.09/pkgs/development/libraries/qt-5/hooks/wrap-qt-apps-hook.sh wrap-qt-hook.sh in nixpkgs] | ||
==== Debugging methods ==== | ==== Debugging methods ==== |
Revision as of 15:46, 28 December 2019
Development
If you want to develop qt applications in nixos you have to use nix-shell or direnv. For using nix-shell just run this command in the terminal:
nix-shell -p qt5Full -p qtcreator --run qtcreator
Tip: if it finds no Qt Kits, rm -rf ~/.config/QtProject*
and start again.
For using direnv, create a shell.nix file in the root of your project and paste these lines into it:
# shell.nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.qt5.full
pkgs.qtcreator
];
}
Tip: if you want use clang-format, add clang-format to buildinputs list.
Also create .envrc file and paste: use_nix
into it.
Happy qt coding :)
Troubleshooting
Cannot mix incompatible Qt library (version 0x_____) with this library (version 0x_____)
This is a known issue, see #30551 for the current status.
Starting with the 19.09 release, the issue should be fixed by #65526
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.
The package will need to be fixed to use [the new https://github.com/NixOS/nixpkgs/issues/65399 wrapQtAppsHook
]. The hook wraps every qt application with adding QT_PLUGIN_PATH
and XDG_DATA_DIRS
as well as XDG_CONFIG_DIRS
.See wrap-qt-hook.sh in nixpkgs
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 patchelf
ing. Exporting LD_DEBUG=libs
may prove helpful in this scenario.