Я использую следующее метод создания элемента:
Код: Выделить всё
QQuickItem *AbstractContent::createFromSource(const QString &source, const QString &objectName)
{
Q_ASSERT_X(engine != nullptr, "init", "ContentHandler FATAL ERROR: QQmlApplicationEngine not inizialised");
QQmlComponent component(engine, QUrl::fromLocalFile(source));
QQuickItem *contentItem = qobject_cast(component.create());
contentItem->setObjectName(objectName);
return contentItem;
}
Код: Выделить всё
auto rootItems = engine->rootObjects();
QObject* contentRect;
if( auto mainWin = qobject_cast(rootItems.at(0)) )
{
contentRect = mainWin->findChild("ContentItem");
}
createFromSource("qmlitem.qml", "objectname")->setParent(contentRect );
Какие методы должны давать желаемый результат?
Подробнее здесь: https://stackoverflow.com/questions/787 ... to-an-exis
Мобильная версия