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 set the header when Image source=https://...?

How to set the header when Image source=https://...?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 4 Posters 616 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.
  • S Offline
    S Offline
    senmx
    wrote on last edited by
    #1
    Image {
      source: "https://xxx.jpg"
      anchors.fill: parent
      fillMode: Image.PreserveAspectCrop
    }
    How to set the header?
    

    Like this:

    QNetworkRequest request;
    request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
    

    Thks!

    eyllanescE 1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I don't think there is a way to do it in QML.

      What you can do is to use an QQuickImageProvider and fetch the image yourself, with correct header, using QNetworkAccessManager.

      (Z(:^

      S 1 Reply Last reply
      1
      • S senmx
        Image {
          source: "https://xxx.jpg"
          anchors.fill: parent
          fillMode: Image.PreserveAspectCrop
        }
        How to set the header?
        

        Like this:

        QNetworkRequest request;
        request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
        

        Thks!

        eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by
        #3

        @senmx Another alternative is to use XMLHttpRequest and convert the raw image to base64(https://doc.qt.io/qt-5/qml-qtqml-qt.html#btoa-method) and set it as the Image source.

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        1 Reply Last reply
        2
        • sierdzioS sierdzio

          I don't think there is a way to do it in QML.

          What you can do is to use an QQuickImageProvider and fetch the image yourself, with correct header, using QNetworkAccessManager.

          S Offline
          S Offline
          senmx
          wrote on last edited by
          #4

          @sierdzio @eyllanesc Thank you very much.

          1 Reply Last reply
          0
          • GrecKoG Online
            GrecKoG Online
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #5

            An alternative is to set a QQmlNetworkAccessManagerFactory with QQmlEngine::setNetworkAccessManagerFactory.

            You can add headers to all your requests or conditionally depending on the URL or something else.

            1 Reply Last reply
            2

            • Login

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