Question about QDeclarativeComponent::setData()
-
Hello, I don't understand the documentation on QDeclarativeComponent::setData(). What does this mean: "If url is provided, it is used to set the component name and to provide a base path for items resolved by this component."?
Am I able to create a component in c++ side based on a QML string and then create an instance of it in QML like this, MyComponent {}?
-
Thanks mohsen for trying to help :) I did not understand your answer though. I know that I can create a QObject derived object or QDeclarativeItem derived object in c++ and then expose it to be used in QML side with qmlRegisterType. I was wondering if I can create the object like this in c++:
QDeclarativeComponent *comp = new QDeclarativeComponent(engine);
comp->setData("import QtQuick 1.1 \n Rectangle{ \n color: "red" \n border.color: "blue" \n border.width : 8 } ");... and then instantiate this component in QML?
I am able to instantiate it in c++ side and the rectangle will appear on screen. I was also able to put it in correct place by setting a proper parent.