Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Trusted Contributor
AllSystemGo
Posts: 140
Registered: ‎11-23-2010
My Device: Torch 9800
My Carrier: Rogers
Accepted Solution

Need some help with NetImageTracker/Manager

Hello all,

 

   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

Please use plain text.
Developer
igosoft
Posts: 71
Registered: ‎09-19-2012
My Device: Z10 very soon
My Carrier: Play

Re: Need some help with NetImageTracker/Manager

Please print the value of feed.vale(url).

Please use plain text.
Developer
Zmey
Posts: 1,511
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Need some help with NetImageTracker/Manager

Hi,

Convert it from QVariant to a string first. I assume feed is QVariantMap of parsed json data and there's 'url' field present.

QString urlString = feed["url"].toString();
nit->setImageSource(QUrl(urlString));


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Trusted Contributor
AllSystemGo
Posts: 140
Registered: ‎11-23-2010
My Device: Torch 9800
My Carrier: Rogers

Re: Need some help with NetImageTracker/Manager

Ok I'll give it a try. But once I do that there is nothing else to do?? How do I get the id and where it has been downloaded?
Please use plain text.
Developer
Zmey
Posts: 1,511
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Need some help with NetImageTracker/Manager

[ Edited ]

You'll need to create a NetImageManager instance which all NetImageTrackers will use:

 

In .hpp:

NetImageManager *manager_;

 

In constructor:

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);
or
NetImageTracker* nit = new NetImageTracker(manager_); // if you want to set manager_ as it's parent

 

Configure ImageTrackers with NetImageManager instance:

 

nit->setManager(manager_);

 

Set image URL to load: (use setSource, not setImageSource as it holds the result)

nit->setSource(QUrl(urlString));

 

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

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Trusted Contributor
AllSystemGo
Posts: 140
Registered: ‎11-23-2010
My Device: Torch 9800
My Carrier: Rogers

Re: Need some help with NetImageTracker/Manager

Thank you for the explanation and the code. I'll give it a try.

Thank you again.
Please use plain text.