10-08-2012 08:44 AM
My app currently uses a custom listview (using a ListItemListener and ListItemProvider) that loads images over the network and displays the appropriate image next to each list item. This works fine for any list items that are currently displayed, but setting the image source for an off-screen list item results in a Segfault at bb::cascades::Image:
perator=() at 0x79446f3c. This happens for both setting the image source to the path of the locally downloaded image, and for tracking that image's state and using setImage().
This particular list works by inserting a container (InnerItem) into my list item. This InnerItem is a container which is replaced by a different instance when the user swipes left or right.
I want to have these images downloaded in the background and displayed in the list item's ImageView as that item scrolls into view, avoiding this segfault. is there any way of achieving this?
Here's some sample code:
For the ListItemListener:
void MyListItemClass::onInnerListChanged() {
mInnerContainer->removeAll();
if(mInnerList.size() > 0) {
InnerItem* innerItem = new InnerItem(mBroadcasts.at(currentIndex));
mInnerContainer->add(innerItem->getContainer);
}
}
For the InnerItem, I can confirm the image has downloaded successfully, but the SegFault only occurs when setting the image source or image:
/*!
* Updates the episode preview image when downloaded
*/
void InnerItem::onImageProcessed(QUrl url) {
if(imgPreview) {
qDebug() << "Image is visible, setting to " << url.toString();
imgPreview->setImageSource(url);
}
/*
// Let's try tracking
mTrack = new ImageTracker(url);
bool result = connect(mTrack, SIGNAL(stateChanged(bb::cascades::ResourceState::T ype)),
this, SLOT(onStateChanged(bb::cascades::ResourceState::T ype)));
Q_ASSERT(result);
Q_UNUSED(result);
*/
}
void EpisodeItem::onStateChanged(bb::cascades::Resource State::Type state) {
if(state == ResourceState::Loaded) {
imgPreview->setImage(mTrack->image());
}
}