02-16-2013 10:54 PM
I need some help understanding how NetImageTracker is working. What I'm trying to achieve is to download images to insert in listview but i'm trying to use it directly from C++. What I have right now is declaring a new Net ImageTracker and then I use the function imageSource but for some reason I can't pass my url in there.
So I have
NetImageTracker* nit = new NetImageTracker(); nit->setImageSource(QUrl(feed.value("url")));
but I don't think that how it's suppose to work. the feed.value("url") is a json file I download from the web
Thank you for the help
Solved! Go to Solution.
02-17-2013 02:23 PM
02-17-2013 03:11 PM - edited 02-17-2013 03:13 PM
You'll need to create a NetImageManager instance which all NetImageTrackers will use:
manager_ = new NetImageManager(this);
When creating ImageTrackers also set their parent so they will be automatically destroyed together with parent:
NetImageTracker* nit = new NetImageTracker(this);
NetImageTracker* nit = new NetImageTracker(manager_); // if you want to set manager_ as it's parent
Configure ImageTrackers with NetImageManager instance:
Set image URL to load: (use setSource, not setImageSource as it holds the result)
Connect to imageSourceChanged signal and when it fires get the URL of downloaded image.
In the signal handler:
NetImageTracker *tracker = (NetImageTracker *)sender();
QString urlStr = tracker->getImageSource();
QUrl url = QUrl(urlStr);
// this url can be used in ImageView
tracker->deleteLater(); // optionally destroy NewImageTracker as it's no longer needed