Alvein
Alvein

Reputation: 207

Code runs fine in IDE, but after deployment I get: module "QtQuick.Controls" is not installed

CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)

project(qq VERSION 0.1 LANGUAGES CXX)

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

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS QuickWidgets)

set(PROJECT_SOURCES
    main.cpp
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(qq
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
else()
    add_executable(qq
        ${PROJECT_SOURCES}
    )
endif()

target_link_libraries(
    qq
    PRIVATE Qt${QT_VERSION_MAJOR}::QuickWidgets
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(qq)
endif()

main.cpp:

#include <QApplication>
#include <QMessageBox>
#include <QtQuickWidgets>

#define QML_TEST R"(
import QtQuick.Controls
Button {}
)"

int main(int argc,char *argv[]) {
    QApplication app(argc,argv);
    QQuickWidget qkwTest;
    qkwTest.setSource(QUrl(
        QStringLiteral("data:text/plain;,%1").
        arg(QStringLiteral(QML_TEST).toUtf8().toPercentEncoding())
    ));
    if(!qkwTest.rootObject())
        for(const auto &e:qkwTest.errors())
            QMessageBox::information(nullptr,"error",e.description());
    else
        QMessageBox::information(nullptr,QString(),"success");
    app.exit();
}

As mentioned, this code gets "success" in the IDE, but when I deploy the program (after using windeployqt), I get the error module "QtQuick.Controls" is not installed.

Notice that I am not using any resource file. For one thing, the actual QML content is very small. Or I could be auto-generating it later. That's not important right now.

The point is, what should I do to avoid this error?

Upvotes: 0

Views: 45

Answers (0)

Related Questions