How to set the header when Image source=https://...?
-
wrote on 9 Sept 2021, 12:44 last edited by
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!
-
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.
-
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!
wrote on 10 Sept 2021, 05:26 last edited by@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.
-
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.
wrote on 10 Sept 2021, 05:50 last edited by@sierdzio @eyllanesc Thank you very much.
-
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/5