[Qt-qml] How to pass Image data from QML to C++ side?
Artem Marchenko
artem.marchenko at gmail.com
Tue Oct 4 13:00:47 CEST 2011
Hi Niko and all
Does this QNetworkDiskCache approach also mean that I need to make images on the QML side get data through my custom image provider using the same cache?
I had a thought about implementing my own image provider in C++ and fetching images for qml from there. Should indeed be efficient and I'll probably try it for the next version. For right now the need to be careful with putting cache files here and there and processing download edge conditions on c++ accurately (e.g. if network goes down in the middle of download) seems to be too much compared to benefits.
I was looking more for ability to pass QMLs QImage to C++ side and save it there. I tried passing it to a C++ slot ( void processImage(const QImage& img);) and then using QImage's save(). It doesn't save the same file, but compresses the image again, that may be good enough for my purposes. Unfortunately save() fails.
Best regards,
Artem.
On Oct 4, 2011, at 12:13 PM, Niko Kähkönen 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).
>>
>> Best regards,
>> Artem.
>>
>
> Hi,
> You can use QNetworkDiskCache in C++ side:
>
> QNetworkAccessManager *manager = new QNetworkAccessManager(this);
> QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
> diskCache->setCacheDirectory("cacheDir");
> manager->setCache(diskCache);
>
> // do a request preferred from cache
> QNetworkRequest request(QUrl(QString("http://qt.nokia.com")));
> request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
> manager->get(request);
>
>
> -Niko
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
More information about the Qt-qml
mailing list