Qt: Difference between revisions

imported>Tobias.bora
No edit summary
Added a section for explicitly specifying development dependencies
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>
<syntaxHighlight lang=nix>
# shell.nix
# shell.nix
Line 27: Line 28:
Happy qt coding :)
Happy qt coding :)


=== Explicit Dependencies ===
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
{ pkgs ? import <nixpkgs> {} }:
let
  # pkgs.qt6.env already includes pkgs.qt6.qtbase
  # And using `with` to prevent a lot of typing.
  qtEnv = with pkgs.qt6; env "qt-custom-${qtbase.version}" {
    [
      qtdeclarative
    ]
  };
in
  pkgs.mkShell {
    buildInputs = [
      qtEnv
      # pkgs.qt6.qtdeclarative depends on pkgs.libglvnd
      # Also worth noting it could be in qtEnv if preferred for "relatedness" reasons
      pkgs.libglvnd
      pkgs.qtcreator
    ];
}
</syntaxHighlight>


== Packaging ==
== Packaging ==