kbalar
kbalar

Reputation: 359

QML: How to set dynamically created component to the Loader

I am creating new QML screen using following code.

var newComp = Qt.createComponent(“test.qml”);
var newObject = newComp.createObject(parent, {“x”: 0, “y”: 0});

I wan to set this component to the loader.

I have tried to do it using Loader.sourceComponent = newObject;

it works but it gives me following error.

“Error: Cannot assign QObject* to QDeclarativeComponent*”

Is there any workaround for this.

Thanks.

Upvotes: 1

Views: 2010

Answers (1)

blakharaz
blakharaz

Reputation: 2590

Loader.sourceComponent has to be a Component, so

Loader.sourceComponent = newComp 

should work.

But this is pretty much the same as

Loader {
    source: "test.qml"
}

Upvotes: 3

Related Questions