[Qt-qml] How to pass Image data from QML to C++ side?

Juha Turunen turunen at iki.fi
Mon Oct 3 19:13:44 CEST 2011


On Mon, Oct 3, 2011 at 6:13 PM, Artem Marchenko
<artem.marchenko at gmail.com> wrote:
> Hi All
>
> My app is some kind of special flickr viewer and is nearly fully done in QML. I want to let user to be able to save some Images to the device. Right now I am passing the Image's URL to the C++ side and download the image using QNetworkManager.
>
> That, however, means that in almost all cases C++ side is going to download the very same file already downloaded on QML side (by setting Image.source property).
>
> Is there a way to avoid double download and pass the Image's data to C++ side to further saving as JPG or PNG (JPG is the original format if it matters).

The first thing that comes to my mind is derive your own
QNetworkAccessManager which contains some logic to save the replies of
the "interesting" requests to some temporary storage on the disk and
when the user wants to save an image the temporary storage can then be
searched and the wanted image moved to a permanent place. The
temporary storage can then be purged occasionally so that the amount
of useless files doesn't accumulate. To know which responses to save
you could tag the url with some pre/suffix on the QML side and then
strip it out before passing it to the normal implementation of QNAM.
You could also implement your own QAbstractNetworkCache to contain the
storage logic.

Juha


More information about the Qt-qml mailing list