[Interest] [Qt6] QML automatic type registration in a (shared) library
Konstantin Shegunov
kshegunov at gmail.com
Fri Jan 14 14:16:16 CET 2022
Hi,
I've been continuing to experiment with the Qt6 QML capabilities and I hit
the following problem. I have a shared library with a couple of qml files,
but for some reason I don't get them installed and when I run the
application I get the module not installed error.
While trying to figure out what I did wrong I listed the resource and I
don't have a path for the library's module at all, so I imagine that'd be
the reason for the error. I do get a qmldir for a C++ piece of code (in
another shared library) fine, though, so I assume something's not correct
with my project, but for the life of me I can't seem to understand what.
Here's what I have for the problematic subproject:
add_library(TscUi SHARED
TscUi.h
TscUi.cpp # This is just a dummy, without it I don't get a .lib file at all
)
add_library(Tsc::Ui ALIAS TscUi)
set_target_properties(TscUi PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
target_include_directories(...)
target_compile_definitions(...)
target_link_libraries(TscUi
PRIVATE Qt::Qml Tsc::Core
)
qt_add_qml_module(TscUi
URI Tsc.Ui
VERSION ${PROJECT_VERSION}
QML_FILES
Main.qml
BottomBar.qml
NO_PLUGIN
)
I've added the NO_PLUGIN, as I explicitly link against this, but for what
it's worth removing it doesn't seem to make any difference. In the
tscui_qmltyperegistrations.cpp I see the module being added, but no types
(in contrast to the code that exposes QML things from C++), is this correct:
Q_QMLTYPE_EXPORT void qml_register_types_Tsc_Ui()
{
qmlRegisterModule("Tsc.Ui", 0, 0);
qmlRegisterModule("Tsc.Ui", 0, 1);
}
Additionally when I configure I get the following warning:
CMake Warning at
C:/QtDesktop/6.2.2/msvc2019_64/lib/cmake/Qt6Qml/Qt6QmlMacros.cmake:694
(message):
The TscUi target is a QML module with target path Tsc/Ui. It uses an
OUTPUT_DIRECTORY of C:/Programming/tsc/build/debug/TscUi, which should end
in the same target path, but doesn't. Tooling such as qmllint may not
work
correctly.
Call Stack (most recent call first):
C:/QtDesktop/6.2.2/msvc2019_64/lib/cmake/Qt6Qml/Qt6QmlMacros.cmake:1453
(_qt_internal_target_enable_qmllint)
C:/QtDesktop/6.2.2/msvc2019_64/lib/cmake/Qt6Qml/Qt6QmlMacros.cmake:576
(qt6_target_qml_sources)
C:/QtDesktop/6.2.2/msvc2019_64/lib/cmake/Qt6Qml/Qt6QmlMacros.cmake:627
(qt6_add_qml_module)
TscUi/CMakeLists.txt:42 (qt_add_qml_module)
Manually forcing
qt_add_qml_module(TscUi
URI Tsc.Ui
... OUTPUT_DIRECTORY
Tsc/Ui
)disposes of it, but also doesn't seem to make any difference for my
registration problem.
If I load from the filesystem the files are parsed properly and
produce the expected result.
As you probably can tell from the paths, I'm using Qt 6.2.2 (from the
maintenance tool) on windows with msvc19.
Any ideas what I did wrong?
Thanks,
Konstantin.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20220114/982815c3/attachment.htm>
More information about the Interest
mailing list