Solved Distinguish between text message and image message sent from server (both encoded in qstring)
-
Use QByteArray directly rather than QString, that will avoid unless conversions.
Also your
label
variable only exists for the lifetime of the if block in case of type being image so it won't even be shown. -
@SGaist After correcting this part too the result was same. I realize I have been mixing QML with QWidgets and that's what is causing problems. Is there any other way of receiving images without using QWidgets?
-
Do you mean showing images ?
-
@Vasudha said in Distinguish between text message and image message sent from server (both encoded in qstring):
block.toBase64();
That is a const method. Do you mean
block=block.toBase64();
? -
@SGaist yes
-
@VRonin yeah
-
QFile file(fileName); if (!file.open(QFile::ReadOnly)) { qDebug() << "Cannot open the selected file"; return; } const QString block = QString::fromLatin1(file.readAll().toBase64()); const QString roomID("rID"); const QString type("image") QJsonObject jSonImage; jSonImage.insert("rid",roomID); jSonImage.insert("type",type); jSonImage.insert("msg",block); sendMessage("sendMessage", QJsonDocument(jSonImage));
-
@VRonin This was very smart. The image is being sent successfully but how to show it (at receiving end) without using QWidgets (after decoding it)?
-
A QtQuick Image element ?
-
Thank you everyone :)