0

I have inlined Component like

Component {
    id: movie_delegate
    MovieListItem {
        movie: movie
    }
}

Now I'm trying to create new object like

movie_delegate.createObject

But there is no such method. But if I do like this:

var comp = Qt.createComponent("MovieListItem.qml");
var o = comp.createObject(model);

Everything works fine.

2 Answers 2

1

Do not inline the component, but use Qt.createQmlObject with a string.

e.g. (from http://doc.qt.nokia.com/4.7-snapshot/qdeclarativedynamicobjects.html#creating-an-object-from-a-string-of-qml)

var newObject = Qt.createQmlObject('import QtQuick 1.0; MovieListItem {movie: movie}', parentItem, "dynamicSnippet1");
Sign up to request clarification or add additional context in comments.

1 Comment

I don't like this way of creating objects since I'm going to make a lot of them, and parsing qml each time is bad idea, with this way parent fields can't be accessed, no compile-time checking and stuff. Anyway I don't have this problem any more, when I solved other error this was fixed with it, which is a little bit weird.
0

This issue has gone when I've fixed other error, which is a little bit weird since they were unrelated, but may be I just don't see relation. Anyway question is closed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.