Component.onCompleted events do not work
-
Hi! I load one qml component into groupbox of another component using this code:
QQmlComponent *comp = new QQmlComponent(engine, QUrl("qrc:/controllers/container.qml"), contentItem()); QObject *obj = comp->create(); QQmlProperty::write(obj, "parent" , QVariant::fromValue<QObject*>(contentItem())); delete comp;But Component.onCreated event do not fires. How to fix this problem?
PS: I do want to Component.onCreated be called after setting parent of loaded component -
Hi! I load one qml component into groupbox of another component using this code:
QQmlComponent *comp = new QQmlComponent(engine, QUrl("qrc:/controllers/container.qml"), contentItem()); QObject *obj = comp->create(); QQmlProperty::write(obj, "parent" , QVariant::fromValue<QObject*>(contentItem())); delete comp;But Component.onCreated event do not fires. How to fix this problem?
PS: I do want to Component.onCreated be called after setting parent of loaded component@Rem-Kolomna If you use create() then
Component.onCompletedwill be called instantly. For more fine tuning you can use beginCreate followed by completeCreate thus calling theComponent.onCompletedevent. So according to your code:QQmlComponent *comp = new QQmlComponent(engine, QUrl("qrc:/controllers/container.qml"), contentItem()); QQuickItem *childItem = qobject_cast<QQuickItem*>(component.beginCreate(engine->rootContext())); childItem->setParentItem(item); //set parent as your requirement qDebug() << "Before calling event"; component.completeCreate();Try printing something inside
Component.onCompletedofcontainer.qmlto notice the change. -
thank you for suggestion! Now everything works like a charm!