qt - Using a Loader for a string of QML -
in qt 5.3 i've been using loader
qml element loading screens, loading view qml file in background. i'm trying load string of qml dynamically. qt.createqmlobject
enables me so, can't seem loader
element play along.
seems loader
takes url (qurl
) or component (qqmlcomponent
), qt.createqmlobject
creates object (qobject
).
i'm new qml, understanding components reusable elements, similar classes, , objects instances of classes. can't seem wrap head around why loader
wouldn't work objects.
how can show loading screen while (asynchronously) parsing , initializing string of qml?
example qml code:
item { rectangle {id: content} loader {id: loader} component.oncompleted: { var obj = qt.createqmlobject('import qtquick 2.3; rectangle {}', content); loader.source = obj; // throws error. } }
it's not possible using current api. loader's documentation says, loads objects via url points qml file or component:
import qtquick 2.0 item { rectangle { id: content anchors.fill: parent color: "grey" loader { id: loader sourcecomponent: mycomponent anchors.fill: parent anchors.margins: 40 } } property component mycomponent: qt.createcomponent("mycomponent.qml", component.asynchronous) }
mycomponent.qml:
import qtquick 2.2 rectangle { color: "red" }
Comments
Post a Comment