Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
6.3.0 Beta2
Description
The attached example program tries to put its Qml files into a "ui" plugin. Motivation is to avoid having the .qml files on the same level as the project's main CMakeLists.txt.
Running the code results in this error message:
QQmlApplicationEngine failed to load component qrc:/ui/main.qml:22:5: Type FooText unavailable qrc:/ui/controls/FooText.qml:3:1: module ":.ui" plugin "uiplugin" not found
- Is there anything wrong with using import ".."? Real life code is full of those imports.
- Using import ".." without the code being bundled in a separate plugin (without the ui subdirectory, using the application target directly) works.
ui/controls/FooText.qml
import QtQuick import ".." // << error message GreenText { color: "red" }
ui/CMakeLists.txt
cmake_minimum_required(VERSION 3.16) qt_add_library(ui STATIC) qt_add_qml_module(ui URI ui VERSION 1.0 QML_FILES main.qml GreenText.qml controls/BlueText.qml controls/FooText.qml )
CMakeLists.txt
cmake_minimum_required(VERSION 3.16) project(untitled11 VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.2 COMPONENTS Quick REQUIRED) qt_add_executable(appuntitled11 main.cpp ) # Qml UI add_subdirectory(ui) set_target_properties(appuntitled11 PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_compile_definitions(appuntitled11 PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>) target_link_libraries(appuntitled11 PRIVATE Qt6::Quick uiplugin )
Attachments
Issue Links
- relates to
-
QTBUG-100450 QML cmake API blogposts need to be converted into documentation pages
- Closed