I am beginning with QT5 and trying to load an image from base64 json data. I can load directly from a base64 string but is unsuccessful when trying to load from json object.
the error i am getting is error: conversion from 'QJsonValueRef' to non-scalar type 'QByteArray' requested
I tried changing toUtf8 toAcsii() etc. but similar error are being produced. Any help and suggestions will be much appreciated.
QString strReply
= (QString)reply
->readAll
();
// json data from a servlet (created using gson library) QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
QJsonObject jsonObj = jsonResponse.object();
QByteArray imgbase64
= jsonObj
["photo"];
// image data img.
loadFromData(QByteArray::fromBase64(imgbase64
));
ui
->outputImage
->setPixmap
(QPixmap::fromImage(img
));
ui->outputImage->setScaledContents( true );
QString strReply = (QString)reply->readAll(); // json data from a servlet (created using gson library)
QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
QJsonObject jsonObj = jsonResponse.object();
QByteArray imgbase64 = jsonObj["photo"]; // image data
QImage img;
img.loadFromData(QByteArray::fromBase64(imgbase64));
ui->outputImage->setPixmap(QPixmap::fromImage(img));
ui->outputImage->setScaledContents( true );
ui->outputImage->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
To copy to clipboard, switch view to plain text mode
Bookmarks