Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to get image data of qml?
Qt 6.11 is out! See what's new in the release blog

How to get image data of qml?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • small_birdS Offline
    small_birdS Offline
    small_bird
    wrote on last edited by small_bird
    #1

    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.

    E 1 Reply Last reply
    0
    • small_birdS small_bird

      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.

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @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).

      small_birdS 1 Reply Last reply
      0
      • E Eeli K

        @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).

        small_birdS Offline
        small_birdS Offline
        small_bird
        wrote on last edited by
        #3

        @Eeli-K Yes, I have got the status, it is 2

        E 1 Reply Last reply
        0
        • small_birdS small_bird

          @Eeli-K Yes, I have got the status, it is 2

          E Offline
          E Offline
          Eeli K
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved