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
cjonesy
Posts: 160
Registered: ‎09-13-2012
My Device: 9900

Trying to load image with qt

Hi,

 

I have placed an png image in the main folder of my project (same as icon) and I am using..

 

QIcon *qq = new QIcon("app/native/testimage.png");

 

but the QIcon is reported as null.

 

What am I doing wrong please? 

 

 

Developer
rashm2k
Posts: 18
Registered: ‎10-12-2012
My Device: Playbook

Re: Trying to load image with qt

[ Edited ]

try this QDir::currentPath()

 

then set your image path relative to that.

 

some more info:

 

http://stackoverflow.com/questions/7402576/how-to-get-current-working-directory-in-a-qt-application

Developer
drPetr007
Posts: 48
Registered: ‎10-11-2012
My Device: Z10

Re: Trying to load image with qt

You have to add your resources to Assets in bar-descriptor.xml .

Just look to examples of native apps provided by BlackBerry Dev Team

Trusted Contributor
cjonesy
Posts: 160
Registered: ‎09-13-2012
My Device: 9900

Re: Trying to load image with qt

Thanks rasm2k,

 

I have just tried

 

 QIcon *qq = new QIcon(QDir::currentPath()+"/pcicon.png"); 

item->setData(Qt::smileyvery-happy:ecorationRole, *qq);

 

but still I cant see the image in my list and my list delegate reports that it is null after casting in its paint function..

 

QIcon ic = QIcon(qvariant_cast<QPixmap>(index.data(Qt::smileyvery-happy:ecorationRole)));

//ic is null after this.

 

I have watched 3 hours passed by trying to put an image in a list - is qt really this difficult?

Trusted Contributor
cjonesy
Posts: 160
Registered: ‎09-13-2012
My Device: 9900

Re: Trying to load image with qt

I have  <asset path="pcicon.png">pcicon.png</asset> in my xml file already.

Developer
jheron
Posts: 188
Registered: ‎01-27-2012
My Device: playbook

Re: Trying to load image with qt

[ Edited ]

Consider using the QResource system for all your embedded images and resources. No need to worry about asset paths and such then.

Then you just access with the path like this: "qrc:/prefix/image.png"

Cheers,

Jon

Trusted Contributor
cjonesy
Posts: 160
Registered: ‎09-13-2012
My Device: 9900

Re: Trying to load image with qt

Thank you all for your replies,

 

it turned out it was the way I was casting the image data in the list delegate, I should have cast to QVariant and then to QIcon, still learning!

 

Regards

 

C