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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Native Development

Reply
Trusted Contributor
cjonesy
Posts: 160
Registered: ‎09-13-2012
My Carrier: vodafone

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? 

 

 

Please use plain text.
Developer
rashm2k
Posts: 18
Registered: ‎10-12-2012
My Carrier: none

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

Please use plain text.
New Developer
drPetr007
Posts: 14
Registered: ‎10-11-2012
My Carrier: none

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

Please use plain text.
Trusted Contributor
cjonesy
Posts: 160
Registered: ‎09-13-2012
My Carrier: vodafone

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?

Please use plain text.
Trusted Contributor
cjonesy
Posts: 160
Registered: ‎09-13-2012
My Carrier: vodafone

Re: Trying to load image with qt

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

Please use plain text.
Developer
jheron
Posts: 183
Registered: ‎01-27-2012
My Carrier: ...

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

Please use plain text.
Trusted Contributor
cjonesy
Posts: 160
Registered: ‎09-13-2012
My Carrier: vodafone

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

Please use plain text.