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. Show an Image by loading data via XmlHttpRequest?
Forum Update on Monday, May 27th 2025

Show an Image by loading data via XmlHttpRequest?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 588 Views
  • 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.
  • SandmanS Offline
    SandmanS Offline
    Sandman
    wrote on last edited by Sandman
    #1

    I need to fetch a jpeg image from a REST API call. I use XMLHttpRequest as the request requires authentication headers (I can't just create an Image and set the source to the URL with user:passwd@url).

    I thought I'd be able to use a Canvas and call drawImage by setting the REST data to a CanvasImageData object. However, it doesn't draw anything, nor does it produce an error. The REST call returns Content-Type: image/jpeg and the Transfer-Encoding: chunked.

    Should this approach work, or am I missing something else? Any better suggestions?

    -BS

    // map_request.imageBytes is a property that holds the binary response from the REST query
    Canvas {
        id: location_map
        width: 2400
        height: 1500
        contextType: '2d'
    
        onPaint: {
          if (context && map_request.imageBytes)
          {
            var cid = context.createImageData(width, height);
            cid.data = map_request.imageBytes;
            context.drawImage(cid, 0, 0);
          }
    }
    
    1 Reply Last reply
    0
    • SandmanS Offline
      SandmanS Offline
      Sandman
      wrote on last edited by
      #2

      I x-posted to stackoverflow, and got some suggestions there that addresses the problem.
      http://stackoverflow.com/questions/36852856/display-image-in-qml-from-response-to-xmlhttprequest-rest

      1 Reply Last reply
      0

      • Login

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