'Can't run my built Qt Design Studio (Qt 6) project with CMake on Windows

I'm trying to run a compiled Qt6 project with CMake and mingw64, however, Qt6 apparently can't find QtQuick.Studio.Effects, QtQuick.Studio.Components and QtGraphicalEffects.

> This is the error log when executing the compiled binary:

QQmlApplicationEngine failed to load component
qrc:Main/main.qml:4:1: Type App unavailable
qrc:/content/App.qml:38:1: module "QtQuick.Studio.Effects" is not installed
qrc:/content/App.qml:37:1: module "QtQuick.Studio.Components" is not installed
qrc:/content/App.qml:35:1: module "QtGraphicalEffects" is not installed
qrc:/content/App.qml:38:1: module "QtQuick.Studio.Effects" is not installed
qrc:/content/App.qml:37:1: module "QtQuick.Studio.Components" is not installed
qrc:/content/App.qml:35:1: module "QtGraphicalEffects" is not installed
qrc:/content/App.qml:38:1: module "QtQuick.Studio.Effects" is not installed
qrc:/content/App.qml:37:1: module "QtQuick.Studio.Components" is not installed
qrc:/content/App.qml:35:1: module "QtGraphicalEffects" is not installed

It runs correctly on the Qt Design Studio preview (Qt6 installed).

> This is the CMake config:

cmake_minimum_required(VERSION 3.18)

project(MeanieProjectApp LANGUAGES CXX)

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

find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui Qml Quick)
add_executable(MeanieProjectApp src/main.cpp)

target_link_libraries(MeanieProjectApp PRIVATE
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::Gui
    Qt${QT_VERSION_MAJOR}::Quick
    Qt${QT_VERSION_MAJOR}::Qml
)

include(${CMAKE_CURRENT_SOURCE_DIR}/qmlmodules)

> The first lines of the App.qml file, containing the imports:

import QtQuick 2.15
import QtQuick.Shapes 1.2
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Controls.Material 2.15
import QtGraphicalEffects 1.15
import QtQuick.Timeline 1.0
import QtQuick.Studio.Components 1.0
import QtQuick.Studio.Effects 1.0

import MeanieProject 1.0

> And finally, main.cpp:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    qputenv("QT_LOGGING_RULES", "qt.qml.connections=false");
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(u"qrc:Main/main.qml"_qs);
    QObject::connect(
                &engine, &QQmlApplicationEngine::objectCreated, &app,
                [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    },
    Qt::QueuedConnection);

    engine.addImportPath(QCoreApplication::applicationDirPath() + "/qml");
    engine.addImportPath(":/");
    engine.addImportPath("qrc:/qml/imports");

    engine.load(url);

    if (engine.rootObjects().isEmpty()) {
        return -1;
    }

    return app.exec();
}

I have correctly set up my two environments variables, going to lib and bin in the mingw64 folder of Qt6.

I'm completely stuck on this, any help is appreciated :) Have a nice day.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source