QML Module Not Found
Solved
Qt Design Studio
-
Hello, I have been scratching my head on this problem for 3 days.
How do I correctly import a custom QML Module into QT Designer. My code compiles fine and works in QT Creator, but when I bring it to QT Design Studio, I cannot seem to get QT Design Studio to be happy with custom modules.
CMake:
cmake_minimum_required(VERSION 3.21.1) option(LINK_INSIGHT "Link Qt Insight Tracker library" ON) option(BUILD_QDS_COMPONENTS "Build design studio components" ON) project(GEO_OSApp LANGUAGES CXX) set(CMAKE_AUTOMOC ON) find_package(Qt6 6.2 REQUIRED COMPONENTS Core Gui Qml Quick SerialPort) if (Qt6_VERSION VERSION_GREATER_EQUAL 6.3) qt_standard_project_setup() endif() qt_add_executable(GEO_OSApp src/main.cpp src/serial.h src/serial.cpp src/admin.h src/admin.cpp src/radialbar.h src/radialbar.cpp src/data.h src/data.cpp ) qt_add_resources(GEO_OSApp "configuration" PREFIX "/" FILES qtquickcontrols2.conf ) target_link_libraries(GEO_OSApp PRIVATE Qt6::Core Qt6::Gui Qt6::Qml Qt6::Quick Qt6::SerialPort ) set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/qml) set(QML_IMPORT_PATH ${QT_QML_OUTPUT_DIRECTORY} CACHE STRING "Import paths for Qt Creator's code model" FORCE ) if (BUILD_QDS_COMPONENTS) include(${CMAKE_CURRENT_SOURCE_DIR}/qmlcomponents) endif() include(${CMAKE_CURRENT_SOURCE_DIR}/qmlmodules) if (LINK_INSIGHT) include(${CMAKE_CURRENT_SOURCE_DIR}/insight) endif () include(GNUInstallDirs) install(TARGETS GEO_OSApp BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) # make IDEs aware of the QML import path set(QML_IMPORT_PATH ${PROJECT_BINARY_DIR}/qml CACHE PATH "Path to the custom QML components defined by the project")
main.cpp:
int main(int argc, char *argv[]) { set_qt_environment(); QGuiApplication app(argc, argv); // Register classes with QML qmlRegisterType<Serial>("Serial", 1, 0, "Serial"); qmlRegisterType<Admin>("Admin", 1, 0, "Admin"); qmlRegisterType<RadialBar>("CustomControls", 1, 0, "RadialBar"); .......
qmldir:
Module GEO_OS singleton Constants 1.0 Constants.qml EventListSimulator 1.0 EventListSimulator.qml EventListModel 1.0 EventListModel.qml DirectoryFontLoader 1.0 DirectoryFontLoader.qml CustomComponents 1.0 RadialBar.qml
-
Solved by updating importPaths in .qmlproject and creating a NEW qmldir file in the actual folder (PROJECT_NAME/imports/MODULE_NAME/qmldir) with the following properties:
module RadialBar RadialBar 1.0 RadialBar.qml
Move the plugin code into PROJECT_NAME/imports/MODULE_NAME/ and call it using import RadialBar 1.0.
Then restart Qt Design Studio.
-