Qt creates component from relative url

The 4.8 docs states that:

When using files with relative paths, the path must be relative to the file where the Qt.createComponent () function is executed.

Therefore, the following is used to create an object:

Qt.createComponent("./foo/bar.qml").createObject(_this)

      

But I am getting error:

QQmlComponent: component not ready

I also tried (no luck) "foo/bar.qml"

. Going to "foobar.qml"

works fine with the directory structure:

./
 +--foo/
 |     `--bar.qml
 `--foobar.qml

      

However, I note that there is no mention of relative urls in the version 5 docs , so is there a new way to do this so I'm missing?

+3


source to share


1 answer


I doubt this is directly related to relative paths. The "Component not ready" error means you are calling createObject()

before the component is ready. Instead, you only need to listen to the component statusChanged

and create the object when the status has changed to Component.Ready

.



See Creating a Dynamic QML Object from JavaScript for a complete example and more details.

0


source







All Articles