How to use qt6?

I am trying to develop a GUI tool using Qt6, and I am using the following shell.nix.

shell.nix

{ pkgs ? import {} }:
pkgs.mkShell {
buildInputs = [
pkgs.qt6.full
pkgs.qtcreator
pkgs.gdb
pkgs.cmake
pkgs.gnumake
pkgs.glibc
pkgs.libcxx
pkgs.gccStdenv
pkgs.gcc-unwrapped
];

shellHook = ‘’
export QT_QPA_PLATFORM=wayland
‘’;
}

However, when I start qtcreator, the following error occurs, how can I troubleshoot the problem?

-- Configuring done
CMake Error at /nix/store/jpwi0aqbzf6km4fkh5fx2f3lrk7wcxd0-qt-full-6.5.2/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:588 (add_executable):
  Cannot find source file:

    /nix/store/jpwi0aqbzf6km4fkh5fx2f3lrk7wcxd0-qt-full-6.5.2/metatypes/qt6core_release_metatypes.json

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc
Call Stack (most recent call first):
  /nix/store/jpwi0aqbzf6km4fkh5fx2f3lrk7wcxd0-qt-full-6.5.2/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:549 (_qt_internal_create_executable)
  /nix/store/jpwi0aqbzf6km4fkh5fx2f3lrk7wcxd0-qt-full-6.5.2/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:741 (qt6_add_executable)
  CMakeLists.txt:11 (qt_add_executable)

The code that is causing the error is as follows, located at /nix/store/jpwi0aqbzf6km4fkh5fx2f3lrk7wcxd0-qt-full-6.5.2/lib/cmake/Qt6Core/Qt6CoreMacros.cmake, line 588.

function(_qt_internal_create_executable target)
    if(ANDROID)
        list(REMOVE_ITEM ARGN "WIN32" "MACOSX_BUNDLE")
        add_library("${target}" MODULE ${ARGN})
        # On our qmake builds we do don't compile the executables with
        # visibility=hidden. Not having this flag set will cause the
        # executable to have main() hidden and can then no longer be loaded
        # through dlopen()
        set_property(TARGET "${target}" PROPERTY C_VISIBILITY_PRESET default)
        set_property(TARGET "${target}" PROPERTY CXX_VISIBILITY_PRESET default)
        set_property(TARGET "${target}" PROPERTY OBJC_VISIBILITY_PRESET default)
        set_property(TARGET "${target}" PROPERTY OBJCXX_VISIBILITY_PRESET default)
        set_property(TARGET "${target}"
                     PROPERTY _qt_android_apply_arch_suffix_called_from_qt_impl TRUE)
        qt6_android_apply_arch_suffix("${target}")
        set_property(TARGET "${target}" PROPERTY _qt_is_android_executable TRUE)
    else()
        add_executable("${target}" ${ARGN})
    endif()

    _qt_internal_set_up_static_runtime_library("${target}")
endfunction()
1 Like

Hi, I’m having the same issue. Did you manage to find a solution?

1 Like

pkgs.qt6.full is broken, please don’t use it.

Have you made it work?

Hello,

So using a nix shell will not work since qtcreator needs to know the locations of allot of libs. A flake approach does work, though.

Check this PR that also fixes the problem you had with the missing metatypes json.