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
Developer
jan_macura
Posts: 20
Registered: ‎08-02-2012
My Device: -

Setting imageSource of StandardListItem from C++ doest not work

Hi all,

 

I have a ListView that is using StandardListItem. Since the images are online, my idea was to download the image and set imageSource from C++. So in imageSource I am calling C++ function with params (image, standardlistitem).

But calling setImageSource function of standardlistitem is not working. I can set everything else like title, description or status but not imageSource. 

 

Here is my StandardListItem and test C++ function:

StandardListItem {

id: root
objectName: "test"
title: ListItemData.title
reserveImageSpace: true
description: ListItemData.description
imageSource: {
root.ListItem.view.getImagePath(ListItemData.image, root)
}
}

 

void App::setImagePath(const QString& url, StandardListItem *item) {

item->setTitle(url); // this works fine
item->setImageSource(QUrl("asset:///images/no_photo_big.jpg")); // this is not working. Console ouput: Context: Failed to find target node with id  367

}

 

Any idea where the problem can be?

 

Thanks,

Jan

Please use plain text.
BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer

Re: Setting imageSource of StandardListItem from C++ doest not work

[ Edited ]

1. Can you do the QUrl line in two lines: create a variable and test myUrl.isValid() and isEmpty

 

2. Can you try with a png file

 

3. If the QUrl is valid and it still doesn't work with a png, can you try the long-winded conversion of QUrl to absolute path in http://supportforums.blackberry.com/t5/Cascades-Development-Knowledge/Using-QImage-and-QPainter-to-P...

 

There are routines there you can just copy:

 

Some judicious qDebug along the way may lead you to the issue.

 

Stuart

 

/*
 * Get the directory containing the images
 */
QString getAssetDir()
{
    // images are in assets/images.
    // This is under app of our initial working directory.
    // Since we don't change directories, it's safe to return a relative path.
    char cwd[PATH_MAX];
    getcwd(cwd, PATH_MAX);
    return QString(cwd) + "/app/native/assets";
}

/*
 * Convert an image url e.g. "asset:///images/Blue_20Nose_20Thumb.png"
 * into a full path that can be opened with routines that don't know asset://
 */
QString getImagePath(QUrl imageUrl)
{
    QString resourceText = imageUrl.toString();
    int index = resourceText.indexOf("/images/");
    return (index > 0)? getAssetDir() + resourceText.mid(index) : resourceText;
}
Please use plain text.
Developer
jan_macura
Posts: 20
Registered: ‎08-02-2012
My Device: -

Re: Setting imageSource of StandardListItem from C++ doest not work

Hi Stuart,

 

1. QUrl is valid and is not empty. Working in other components like ImageView OK.

2. Same problem with png file.

3. I tried absolute path as well, but it didn't solve my problem.

 

void App::getImagePath(const QString& url, StandardListItem *item) {
QString path = getImagePath(QUrl("asset:///images/picture1.png"));
qDebug() << path;
QUrl myUrl(path);

if (myUrl.isValid() && !myUrl.isEmpty()) {
qDebug() << "url is valid";
item->setImageSource(myUrl);
qDebug() << item->imageSource().toString(); // imageSource is set and printed OK, but no image is displayed in ListView

item->setTitle(myUrl.toString()); // title is set and changed in ListView
}

}

 

Anything other idea?

 

Thanks,

Jan

Please use plain text.
BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer

Re: Setting imageSource of StandardListItem from C++ doest not work

I set a breakpoint in cascadescookbookcpp sheet where it makes this call in SheetRecipe::smileysurprised:nNewFruitChanged

newFruitPath is "assets/images/sheet/fruit3.png"

 

Stuart

Please use plain text.
Developer
jan_macura
Posts: 20
Registered: ‎08-02-2012
My Device: -

Re: Setting imageSource of StandardListItem from C++ doest not work

This is working in a standalone ImageView, but still not working in ListView's listItemComponents. ImageSource is set (onImageSourceChanged signal emited), but the image is not displayed(rendered) in ListView.

Please use plain text.
Developer
rock_win
Posts: 136
Registered: ‎02-01-2009
My Device: Not Specified

Re: Setting imageSource of StandardListItem from C++ doest not work

I was also facing similar issue, what i have found with the assets is: if you already have them packaged and not downloaded during runtime.

The best way to solve the issue is by using the absolute path in the Datamodel at the first time itself.

for Later updates, the GDM has issues which I have logged in the issue tracker, but not sure when it would be taken up by RIM since there are no votes to it.

Let us know if you still struggle with the images!

Please use plain text.
BlackBerry Development Advisor (Retired)
amarcon
Posts: 155
Registered: ‎07-16-2012
My Device: Dev Alpha

Re: Setting imageSource of StandardListItem from C++ doest not work

Hi rock_win,

 

You're talking about this one http://supportforums.blackberry.com/t5/Cascades-Development/Unable-to-render-the-ListComponent-Image... ?

 

Can you post the bug you've raised for that?

 

Thanks in advance,

Please use plain text.