[Qt-qml] How to pass Image data from QML to C++ side?
Niko Kähkönen
Niko.Kahkonen at cybercom.com
Tue Oct 4 11:13:52 CEST 2011
> 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
More information about the Qt-qml
mailing list