Reputation: 21
I'm new in Qt quick app. (QML)
I wanna create dynamic image table(like in Samegame example) but it using thread to make real-time create by using workerScript.
How to using WorkerScript by Qt function can be passed between the new thread and the parent thread? or can import Qt func in javascript?
example
//main.qml import QtQuick 1.0
Rectangle {
width: 800; height: 600
WorkerScript {
id: myWorker
source: "script.js"
}
Item {
id: container
anchors.fill: parent
}
Component.onCompleted: myWorker.sendMessage({ 'container':container })
}
//script.js
WorkerScript.onMessage = function(message) {
// error occur in this below line with TypeError: Result of expression 'Qt.createComponent' [undefined] is not a function.
var component = Qt.createComponent("Imgbox.qml");
if (component.status == Component.Ready) {
var img = component.createObject(message.container);
}
}
//Imgbox.qml
import QtQuick 1.0
Image {
id: img
source: "./img.jpg"; clip: true
}
Thanks.
Upvotes: 2
Views: 945
Reputation: 1701
Components cannot be created in a thread. If it is just the cost of loading the image that is the problem, you can load them in the background by setting asynchronous: true
Upvotes: 1