Qt: Difference between revisions
Added a section for explicitly specifying development dependencies |
|||
| (5 intermediate revisions by 2 users not shown) | |||
| Line 16: | Line 16: | ||
pkgs.mkShell { | pkgs.mkShell { | ||
buildInputs = [ | buildInputs = [ | ||
pkgs.qt5.full | |||
pkgs.qtcreator | |||
]; | |||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Also create '''.envrc''' file and paste: <code>use_nix</code> into it. | Also create '''.envrc''' file and paste: <code>use_nix</code> into it. | ||
| Line 32: | Line 30: | ||
However if fetching the entirety of <code>pkgs.qt6.full</code> is not appealing and you know which parts of Qt you need, your first instinct might be adding something like <code>pkgs.qt6.qtdeclarative</code> for creating QML-based Qt programs to <code>buildInputs</code>, '''however''' that will not work and you will get compile errors for missing libraries. <code>pkgs.qt6.full</code> is actually [https://github.com/NixOS/nixpkgs/blob/nixos-24.11/pkgs/development/libraries/qt-6/default.nix#L94-L144 creating an environment that contains all Qt libraries] that allows <code>qmake</code> and tools to find those libraries, so you must do the same and <code>pkgs.qt6.env</code> will help make one. For example: | However if fetching the entirety of <code>pkgs.qt6.full</code> is not appealing and you know which parts of Qt you need, your first instinct might be adding something like <code>pkgs.qt6.qtdeclarative</code> for creating QML-based Qt programs to <code>buildInputs</code>, '''however''' that will not work and you will get compile errors for missing libraries. <code>pkgs.qt6.full</code> is actually [https://github.com/NixOS/nixpkgs/blob/nixos-24.11/pkgs/development/libraries/qt-6/default.nix#L94-L144 creating an environment that contains all Qt libraries] that allows <code>qmake</code> and tools to find those libraries, so you must do the same and <code>pkgs.qt6.env</code> will help make one. For example: | ||
< | <syntaxhighlight lang="nix"> | ||
# shell.nix | # shell.nix | ||
{ pkgs ? import <nixpkgs> {} }: | { pkgs ? import <nixpkgs> {} }: | ||
| Line 38: | Line 36: | ||
# pkgs.qt6.env already includes pkgs.qt6.qtbase | # pkgs.qt6.env already includes pkgs.qt6.qtbase | ||
# And using `with` to prevent a lot of typing. | # And using `with` to prevent a lot of typing. | ||
qtEnv = with pkgs.qt6; env "qt-custom-${qtbase.version}" | qtEnv = with pkgs.qt6; env "qt-custom-${qtbase.version}" [ | ||
qtdeclarative | |||
]; | |||
in | in | ||
pkgs.mkShell { | pkgs.mkShell { | ||
| Line 53: | Line 49: | ||
]; | ]; | ||
} | } | ||
</ | </syntaxhighlight> | ||
== Packaging == | == Packaging == | ||
| Line 196: | Line 192: | ||
== Troubleshooting == | == Troubleshooting == | ||
=== This application failed to start because it could not find or load the Qt platform plugin ??? in "" === | === This application failed to start because it could not find or load the Qt platform plugin ??? in "" === | ||
{{warning|This recommendation is deprecated for 19.09 and up, see {{issue|65399}}. Failing packages should be updated to use <code>wrapQtAppsHook</code>.}} | {{warning|This recommendation is deprecated for 19.09 and up, see {{issue|65399}}. Failing packages should be updated to use <code>wrapQtAppsHook</code>.}} | ||
<pre> | <pre> | ||
| Line 234: | Line 204: | ||
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-apps-hook.sh in nixpkgs] | 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-apps-hook.sh in nixpkgs] | ||
=== Debugging methods === | |||
As a general rule, exporting <code>QT_DEBUG_PLUGINS=1</code> make qt print where it looks for plugins. | As a general rule, exporting <code>QT_DEBUG_PLUGINS=1</code> make qt print where it looks for plugins. | ||
If a plugin exists in a directory but is ignored with a message like <code>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: "</code> it can be that the library cannot be <code>dlopen()</code>ed because of dependencies/rpath issues and needs <code>patchelf</code>ing. Exporting <code>LD_DEBUG=libs</code> may prove helpful in this scenario. | If a plugin exists in a directory but is ignored with a message like <code>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: "</code> it can be that the library cannot be <code>dlopen()</code>ed because of dependencies/rpath issues and needs <code>patchelf</code>ing. Exporting <code>LD_DEBUG=libs</code> may prove helpful in this scenario. | ||