Unsolved How to get image data of qml?
-
Hello everyone, now I have the imageProvider to transmit QImage to qml image element. But I want to get the qimage data of qml image, how to do that? Could anyone help me? Thanks in advance!
import ... as GLCode Image { id: image; asynchronous: true; cache: false; fillMode: Image.PreserveAspectFit; Connections { target: readIrdvDataThread; onCallQmlRefeshImg: { image.source=""; //image: image.source= "image://screen"; console.log(image.sourceSize); GLCode.changeTexture(image); } } } //This is the javascript function I use to get qml Image data. function changeTexture(image) { texture = new THREE.TextureLoader().load(image); console.log("image.width: ",image.width); }
The width shows 0! That's to say, the code failed to load image from qml.
-
@small_bird Of course it wasn't loaded when you called changeTexture; loading is asynchronous. You have to catch the status change (see the docs for the 'status' property of Image).
-
@Eeli-K Yes, I have got the status, it is 2
-
@small_bird Try
onCallQmlRefeshImg: { image.source=""; //image: console.log("before source is set, status " + image.status) image.source= "image://screen"; console.log("after source is set, status " + image.status) console.log(image.sourceSize); GLCode.changeTexture(image); }
and
onStatusChanged: { console.log("image status changed, new status: " + image.status + ", source: " + image.source) }
(and keeping console.log in changeTexture)
to see in which order they happen.