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