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.

Qt Code:
  1. QString strReply = (QString)reply->readAll(); // json data from a servlet (created using gson library)
  2. QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
  3. QJsonObject jsonObj = jsonResponse.object();
  4. QByteArray imgbase64 = jsonObj["photo"]; // image data
  5. QImage img;
  6. img.loadFromData(QByteArray::fromBase64(imgbase64));
  7. ui->outputImage->setPixmap(QPixmap::fromImage(img));
  8. ui->outputImage->setScaledContents( true );
  9. ui->outputImage->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
To copy to clipboard, switch view to plain text mode