Interception of required properties within c++
-
Hi everyone.
I have a c++ classMyClass
and declaratively instantiate it inQML
like:MyClass { required property int foo required property double bar required property string baz }
There is a way to intercept and initialize this properties at c++ side?
Q_PROPERTY
is not used. -
Hi everyone.
I have a c++ classMyClass
and declaratively instantiate it inQML
like:MyClass { required property int foo required property double bar required property string baz }
There is a way to intercept and initialize this properties at c++ side?
Q_PROPERTY
is not used. -
I know, but application crashes with error about not initialized required properties before I have call
QMetaProperty::write
.How do you instantiate the object?
-
I know, but application crashes with error about not initialized required properties before I have call
QMetaProperty::write
.@magrif said in Interception of required properties within c++:
but application crashes with error about not initialized required properties
That has nothing to do with the C++ part.
You wrote "required". Which implies you created a new qml file, right?Then when someone actually USES that new QML file, they are required to provide those properties.
Like:
Foo.qml Item { required property int foo; } Bar.qml Item { Foo { foo: 1 // required property is provided here! } }
-
@GrecKo said in Interception of required properties within c++:
How do you instantiate the object?
@magrif said in Interception of required properties within c++:
declaratively instantiate it in QML
@TomZ said in Interception of required properties within c++:
Then when someone actually USES that new QML file, they are required to provide those properties.
@magrif said in Interception of required properties within c++:
There is a way to intercept and initialize this properties at c++ side?
-
I mean set values somewhere inside
MyClass
. May be some private interfaces or likeQQmlParserStatus
. -
@GrecKo No problem. I want make object with shared properties. For instance in one part of application create:
MyClass { property int foo: 100 roperty double bar: 500.0 property string baz: "Hello" }
The values of properties will be saved inside a c++-side data structure, details here doesn't matter. And somewhere else initialize them to eponymous properties, if they marked as required:
MyClass { required property int foo required property double bar required property string baz }
I would be use and without required keyword, just see if property have value or not. And just initialize it by shared value if no have one . But for primitive types
(bool, int)
its respectivelyQVariant(bool, false)/QVariant(int, 0)
rather thanQVariant(Invalid)
.So I'm trying figure out how it works inside
Qt
.