Reputation: 348
I'm using Qt 6.6 with Qt Design Studio 4.3.
I would like to create a QML module for Qt Design Studio that will be a mockup replacement for a Backend
C++ module.
I would like a structure like that:
MyProject
+ CMakeLists.txt
+ Backend <-- this is my C++ backend module (works fine in Qt Creator)
+ CMakeLists.txt
+ backend.h <-- defines a QML singleton that will fills a model from an external source
+ backend.cpp
+ imports
+ ... <-- qml modules imported to Qt Design Studio and used in the final product
+ content
+ ...
+ designer <-- this would contains design-only modules to use with Qt Design Studio
+ Backend <-- this is a replacement module for the C++ backend module
+ qmldir <-- adds Backend.qml in the module as a singleton
+ Backend.qml <-- defines a ListModel with some mockup items
From the qt documentation:
If you want to use a different module in the Design mode than in your actual application for example to mockup C++ items, you can use QML_DESIGNER_IMPORT_PATH in the .pro file (for qmake projects), or declare and set the property qmlDesignerImportPaths in your product (for Qbs projects). Modules in the import paths defined in QML_DESIGNER_IMPORT_PATH will be used only in the Design mode.
It should be possible to define a QML_DESIGNER_IMPORT_PATH
in a .pro file to achieve what I want (the Contact List example demonstrates that).
However, I have a CMake project, not a qmake one.
I think maybe it could be possible to define it for a CMake project like with QML_IMPORT_PATH
but that doesn't seem to work:
set(QML_DESIGNER_IMPORT_PATH ${CMAKE_BINARY_DIR}/designer CACHE STRING "" FORCE)
There is also the importPaths
member in the .qmlproject
file that defines where to search QML modules.
But I dont know if it exists a similar member for paths of design-only modules.
I tried something like designerImportPaths
or importPathsDesigner
but it doesn't seem to work.
I'm always getting the following error:
Line: 12: QML module not found (Backend).
Import paths:
D:/Qt/Tools/QtDesignStudio/qt6_design_studio_reduced_version/qml
D:/Projects/Qt/MyProject/asset_imports
D:/Projects/Qt/MyProject/imports
For qmake projects, use the QML_IMPORT_PATH variable to add import paths.
For Qbs projects, declare and set a qmlImportPaths property in your product to add import paths.
For qmlproject projects, use the importPaths property to add import paths.
For CMake projects, make sure QML_IMPORT_PATH variable is in CMakeCache.txt.
For qmlRegister... calls, make sure that you define the Module URI as a string literal.
Upvotes: 1
Views: 230