Home > Enterprise >  CMake, Qt6 - module "QtQuick.Controls" is not installed
CMake, Qt6 - module "QtQuick.Controls" is not installed

Time:11-05

I'm currently working on learning QtQuick, and I've been running into a variety of issues, but this is the first one I've been unable to solve so far. For background, I'm using MVSC, Visual Studio 2019, CMake, and Qt6.

Upon running my very basic program, I'm getting the error module "QtQuick.Controls" is not installed on my import statement for QtQuick Controls in the main.qml file I made. The relevant part of the CMakeLists.txt file I'm using is:

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

find_package(Qt6 COMPONENTS Quick REQUIRED)
find_package(Qt6 COMPONENTS QuickControls2 REQUIRED)
find_package(Qt6 COMPONENTS Core REQUIRED)
find_package(Qt6 COMPONENTS Gui REQUIRED)

qt_add_executable(nameHere
    "src/main.cpp"
    "gui/main.qml"
)

target_link_libraries(nameHere PRIVATE Qt6::Quick Qt6::QuickControls2)

qt_import_plugins(nameHere QWindowsIntegrationPlugin )

Note: I've got some extra find packages in there from searching for solutions - removing or adding Gui or Core does not change the error

Upon checking the build folder, these dlls are there:

  • Qt6Gui
  • Qt6Core
  • Qt6Network
  • Qt6OpenGL
  • Qt6Qml
  • Qt6QmlModels
  • Qt6Quick

main.cpp looks like the following:

#include <QtQuick>
#include <QtQuickControls2>

int main(int argc, char* argv[])
{
    QGuiApplication app(argc, argv);

    QQuickView* view = new QQuickView;
    view->setSource(QUrl::fromLocalFile("../../gui/main.qml"));
    view->show();
    return app.exec();
}

The contents of the main.qml file are

import QtQuick 
import QtQuick.Controls

ApplicationWindow {
    id: window
    width: 400
    height: 500
    visible: true

}

Once again, the full error is:

/gui/main.qml:2:1: module "QtQuick.Controls" is not installed
     import QtQuick.Controls
     ^
/gui/main.qml: module "QtQml.WorkerScript" is not installed
/gui/main.qml:2:1: module "QtQuick.Controls" is not installed
     import QtQuick.Controls
     ^
/gui/main.qml: module "QtQml.WorkerScript" is not installed

Any help would be greatly appreciated!


Some further digging through my vcpkg files indicates there is in fact a Qt6QuickControls2.dll that isn't being placed into the build folder. I'm not a fan of just copy and pasting the file into the build folder. I'm not sure why all of the other Qt dlls are being placed into that folder by CMake, but not this specific dll. Is there something that I'm missing from my CMake file, or could this be a bug with how Qt is set up with CMake?


As well, just going ahead and copying the QuickControls2 dll file into the folder doesn't actually fix the problem, so I think there is something else going on here.


Well, in Qt6, QucikControls2 is included in QtQuick, so I'm not sure if it actually needs that extra dll? Not sure what's going on here, but I even went and ran windeployqt, and it says I've already got all of the needed runtime dependencies. Now I have no idea where this issue is coming from.

CodePudding user response:

Qml files should not be linked in the qt_add_executable. In Qt6, use

qt_add_qml_module(nameHere
    URI gui
    VERSION 1.0
    QML_FILES gui/main.qml)

See the documentation here: https://doc-snapshots.qt.io/qt6-dev/qt-add-qml-module.html

  • Related