Solved QML_NAMED_ELEMENT and QML_IMPORT_NAME in VC'2019
-
Hi;
How to use QML_NAMED_ELEMENT and QML_IMPORT_NAME in VC'2019 like Qt Creator ?
Thanks.
-
-
Thanks but this document does not describe good enough (for VC'2019), use qmlRegisterTypesAndRevisions and qmlRegisterModule...
-
@VeNToR
why is this dependent on the compiler in use?! -
@raven-worx
Because I couldn't find where is the definition of QML_IMPORT_NAME in VC'2019... -
@VeNToR
so you are talking about Visual Studio (the IDE) and not the compiler.
The new qml type registration is only available with qmake so far. (https://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/qmltyperegistrar/qmltypes.prf)
Qt6 will introduce support for CMAKE too.
I dont know about the Visual Studio Qt plugin.See the comments in the article
-
@raven-worx thanks for your time. I am reading now !...
-
@raven-worx said in QML_NAMED_ELEMENT and QML_IMPORT_NAME in VC'2019:
The new qml type registration is only available with qmake so far. (https://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/qmltyperegistrar/qmltypes.prf)
Qt6 will introduce support for CMAKE too.Is there a way to get around this? I need to import classes from C++ into QML, I have tested it with qmake (QML_IMPORT_NAME) and it works. But I really wanted to use CMake, because I'm porting an existing project to Qt, and it uses some external libraries with FetchContent.
-
@barrett9h
sure, you dont need to use those newer macros.
See how it's done before those macros were introduced (and is still a valid way AFAIK):
https://doc.qt.io/archives/qt-5.9/qqmlextensionplugin.html#plugin-exampleBasically you need to handle the qml type registration yourself. I personally prefer this way for now, since you are also able to declare multiple import uris which isn't possible with the newer macros (only when you create a separate static lib project and link them together)
-
FYI: since Qt 6.2 you can use the qt6_add_qml_module() method in cmake.