Hi,

Thanks for the info, I did took a look at the QML_ELEMENT at 
https://www.qt.io/blog/qml-type-registration-in-qt-5.15

I was a bit confuse about how this actually do the the convertion between 
people and person in the following example given:



***********************

qmlRegisterType<Person>("People", 1,0, "Person");



This would register the C++ class "Person" as a QML element also called 
"Person", into the module "People" under the version 1.0. This line has 
disappeared in Qt 5.15. Instead, the following lines have been added to the 
adding.pro file:



CONFIG += qmltypes

QML_IMPORT_NAME = People

QML_IMPORT_MAJOR_VERSION = 1



These lines specify the import name and major version for all types exposed to 
QML. Finally, the most important change, is the "QML_ELEMENT" macro added to 
the person.h file:



class Person : public QObject

{

    Q_OBJECT

    Q_PROPERTY(QString name READ name WRITE setName)

    Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)

    QML_ELEMENT

public:

    Person(QObject *parent = nullptr);

    [...]

};

***********************

how does the Person class is link to the People name exactly?!? I do not 
understand how can it known that the C++ class should be link the given People 
import name?! Is like a stack, if I change the QML_IMPORT_NAMES before using 
any HEADERS += or SOURCES += ? like this:



CONFIG += qmltypes

QML_IMPORT_NAME = People

QML_IMPORT_MAJOR_VERSION = 1



HEADERS += Person.h

SOURCES += Person.cpp



QML_IMPORT_NAME = MyOtherModule

QML_IMPORT_MAJOR_VERSION = 1



HEADERS += MyOtherClass.h

SOURCES += MyOtherClass.cpp



Is that how it should work? Is the order of declaration into .pro and .pri 
matter to make this work or there is something I don’t get here? Thanks



-----Original Message-----
From: Ulf Hermann <ulf.herm...@qt.io>
Sent: September 12, 2020 3:24 AM
To: Jérôme Godbout <godbo...@amotus.ca>; interest@qt-project.org
Subject: Re: [Interest] QML/C++ interaction in Qt6



> Will Qt 6 still use the Meta information to access Qml properties or

> it rely more on compiled C++ now? I guess it still the same as before.

> Is the properties declaration of Qt for MCU (Qml lite or soemthign

> like that) be available (syntax wise, template)? That would leverage

> soo much redundent code to expose properties with get/set and changed

> event. That will be a slim fast for code that expose to Qml (to Meta

> data actually, Qml use the meta data) and maybe event make that layer

> disapear one day.



Registration of C++ types for QML in dev is largely unchanged from 5.15.

You get the QML_ELEMENT etc. macros we introduced in 5.15 to make the 
registration as painless as possible. The indirection through the metatype 
system is necessary for the case of dynamically interpreted QML. We can 
generate C++ code from your QML to directly access your C++ types, but if you 
want to execute that same QML in interpreted mode, those C++ types need to be 
visible to metatype system in order to be accessible.



Also, the new property system is being introduced. If you provide a BINDABLE 
property, you may be able to skip the READ, WRITE, and NOTIFY methods in the 
future. This is still being worked on, though.



best,

Ulf
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to