I’m attempting to compile a Qt example project (Document Viewer | Qt 6.11, source download documentviewer « demos « examples - qt/qtdoc.git - Qt Documentation), but I can’t figure out how to set up a shell with the proper libraries. I’m making my shell with
{
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=25.11";
outputs = { self, nixpkgs }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
qtEnv = with pkgs.qt6; env "qt-custom-${qtbase.version}" [
qtdeclarative
qtbase
];
in
{
devShells.x86_64-linux.default = pkgs.mkShell {
buildInputs = [
qtEnv
pkgs.libglvnd
];
shellHook = ''
echo entered dev shell
'';
};
};
}
This is a flake form of the shell.nix from Qt - Official NixOS Wiki.
My build process is:
nix develop
qmake -project
qmake
make
make fails with the output:
g++ -c -pipe -O2 -Wall -Wextra -fPIC -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -I/nix/store/zp6r9bxds1hldvkx1vbrk0d1ady17zhh-qtbase-6.10.1/include -I/nix/store/zp6r9bxds1hldvkx1vbrk0d1ady17zhh-qtbase-6.10.1/include/QtGui -I/nix/store/zp6r9bxds1hldvkx1vbrk0d1ady17zhh-qtbase-6.10.1/include/QtCore -I. -I/nix/store/7s6lgprlql0y0pfshsdyp7alxcc2x8kp-qt-custom-6.10.1/mkspecs/linux-g++ -o abstractviewer.o app/abstractviewer.cpp
app/abstractviewer.cpp:7:10: fatal error: QApplication: No such file or directory
7 | #include <QApplication>
| ^~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:1958: abstractviewer.o] Error 1
Qtbase should include QApplication (I think?), so it should be there somewhere in the environment. I’ve looked at the source for qt6.env, but I honestly can’t figure what what it’s doing. Most of the existing examples I can find use qt6.full or qt5.full, which was removed in 25.11.
Edit: I just noticed that QApplication is a part of Qt Widgets, not Qt Core, so it makes sense it’s not being found (at least in the expression in the makefile). Where on Earth is Qt Widgets packaged? I searched in nixpkgs and grepped around nixpkgs/pkgs/development/libraries/qt-6/, but Qt Widgets doesn’t appear anywhere in there, as far as I can tell.
1 Like
Your qmake project.pro file got overridden by qmake’s generator. For your project to compile, that file should include the widgets library. Something like QT += widgets. I don’t know why qmake failed to register widgets as a dependency, but if you add it manually, then run qmake and make again, it should compile.
EDIT: According to QT’s documentation they mention it is very likely the generated project file needs to be edited. So that is probably why. It only generates a basic project configuration
This was a stupid mistake on my part. I should’ve been using cmake. (I assumed that qmake used cmake internally…). Part of learning, right?
Anyways, for future reference, this flake creates an appropriate shell:
{
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=25.11";
outputs = { self, nixpkgs }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
qtEnv = with pkgs.qt6; env "qt-custom-${qtbase.version}" [
qtdeclarative
qtbase
qttools
wrapQtAppsHook
];
in
{
devShells.x86_64-linux.default = pkgs.mkShell {
buildInputs = [
pkgs.cmake
qtEnv
pkgs.libglvnd
];
shellHook = ''
echo entered dev shell
'';
};
};
}
cmake finds the appropriate libraries in that shell.
EDIT:
I was having trouble getting the built executable to load the Wayland plugin, so I forwent the strange qtEnv expression I got from the wiki. I didn’t want to follow the Nix package approach since I’m using this to learn, not just to make a working package. This is my new flake:
{
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=25.11";
outputs = { self, nixpkgs }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in
{
devShells.x86_64-linux.default = pkgs.mkShell {
buildInputs = [
pkgs.cmake
pkgs.libglvnd
pkgs.kdePackages.qtdeclarative
pkgs.kdePackages.qtbase
pkgs.kdePackages.qttools
pkgs.kdePackages.wrapQtAppsHook
pkgs.kdePackages.qt3d
pkgs.kdePackages.qtquick3d
pkgs.kdePackages.qtwayland
pkgs.kdePackages.qtbase
pkgs.kdePackages.qtnetworkauth
pkgs.kdePackages.qtscxml
pkgs.kdePackages.qtsvg
pkgs.kdePackages.qtwayland
pkgs.kdePackages.qtwebengine
pkgs.kdePackages.qt5compat
pkgs.kdePackages.qtmultimedia
pkgs.kdePackages.qtshadertools
];
shellHook = ''
echo entered dev shell
'';
};
};
}
It’s a little messy. I’ll clean it up in the future. (There are a bunch of unnecessary dependencies in there; I just copied and pasted a large list of dependencies from the Digikam package.)
To get the Wayland plugin working, I wrap the built executable with wrapQtApp as in Running locally built Qt apps - #2 by wamserma.
I hope some of this is useful to someone in the future. The documentation is a little arcane.