1
我是Qt快速應用程序的新手。 (QML)可以在WorkerScript函數中使用Qt.createComponent()嗎?
我想創建動態圖像表(如在Samegame示例中),但它使用線程通過使用workerScript進行實時創建。
如何通過Qt函數使用WorkerScript可以在新線程和父線程之間傳遞?或者可以在JavaScript中導入Qt func?
例如
//main.qml 進口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
}
由於。