Unsolved QQmlComponent initialization from C++
-
i have an application which sets properties of Qml from C++, so far i was able to set property of any type. I am able to create QQmlComponent in C++ and set it to property.
But first i need to initialize component with its properties. I can do that with create/beginCreate and set properties. But i cant change created QObject back to QQmlComponent, therefor i cant set it to givent Component type property.
Is there some way how to conver QObject to QQmlComponent ? Or is there any other way to initialize QQmlComponent properties ?
Example, of what i want to achiev in C++, how it looks in qml
import QtQuick 2.3 Loader { // property of type Component sourceComponent: Text { text: "property i want to intialize, this component can be in file" } }
-
@Kwan said in QQmlComponent initialization from C++:
QQmlComponent
Not entirely sure if I understood you correctly, but take a look at subclassing QQmlParserStatus for your custom QObject (see: https://doc.qt.io/qt-5/qqmlparserstatus.html). You must implement both methods, but the one you are looking for should be "classBegin".
-
-
@Kwan said in QQmlComponent initialization from C++:
i have an application which sets properties of Qml from C++
That smells bad but ok.
How are you creating your
QQmlComponent
? With urls/filename or bytearray data or in an other way?
Anyway you could subclassQQmlComponent::beginCreate
and set your properties there I believe.