Solved How set source for Image - function on c++
-
Hi!
I have function on c++, this function return QImage.
How I can set source for Image - this function? -
-
@VRonin Why do that? My function creates and returns QImage on its own.
How to set the returned QImage for Image in qml? -
For not large images you can convert them to a string using Base64 format. Not optimal but kind of acceptable. For large images it is better to use QQuickImageProvider.
-
I use this code, but Image in qml not use thes string.
How fix this?QString resultString; QByteArray ba; QBuffer bu(&ba); bu.open(QIODevice::WriteOnly); image.save(&bu, "PNG"); resultString = QString::fromLatin1(ba.toBase64().data()); qDebug()<<"resultString = QString::fromLatin1"<<resultString; return resultString;
And this too not work
resultString = ba.toBase64();
-
It is work
QString resultString; QByteArray ba; QBuffer bu(&ba); bu.open(QIODevice::WriteOnly); image.save(&bu, "PNG"); //resultString = QString::fromLatin1(ba.toBase64().data()); resultString = QString::fromLatin1("data:image/png;base64,") + QString::fromLatin1(ba.toBase64().data()); qDebug()<<"resultString = QString::fromLatin1"<<resultString; return resultString;
-
@Mihaill using image provider class, the qt example shows it.