I'mt想补充一点,我将创建由C已经加载另一个QML视图++的自定义QML元素。添加/插入动态QML元素QML将与视图C++
上下文如下:我加载从C++一个QML视图,我需要注入我建立到这个QML视图另一QML定制组件。全部用C++。
我一直在寻找4小时,我还没有找到一种方法来acomplish这一点。
下面是一些代码给你一个更好的视角:
QmlDocument *qml = QmlDocument::create("asset:///PosicionConsolidad.qml").parent(this);
qml->setContextProperty("pos", this);
Page *page = qml->createRootObject<Page>();
myST = GlobalST::getInstance();
LoadInfo();
_mRoot->push(page);
_app->setScene(_mRoot);
void Project::LoadInfo() {
QmlDocument *qml = QmlDocument::create("asset:///customComponents/TableRow.qml").parent(this);
//Here's where I need to append this new QML custom element to the
//page previously loaded.
//I don't know if I can just inject it or I need to make a find child to
//maybe a parent container in the QML view and then add it there. But I
//also tried that and didn't work out.
}
请帮助。问候。
我认为你找到的方法是正确的方法。我们绝不会将组件添加到页面中,而是添加到Container中。 – Benoit