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
Highlighted
Developer
Posts: 38
Registered: ‎09-27-2012
My Device: 9930
My Carrier: airtel
Accepted Solution

Passing QByteArray image from c++ to QML

Hi all,


I need to show a png image in a QML page using a QByteArray passed from c++ routines to QML.Is it possible to do so...?

Is there any simple method to it.?

Developer
Posts: 44
Registered: ‎05-22-2013
My Device: Blackberry 10
My Carrier: 02

Re: Passing QByteArray image from c++ to QML

yes, take a lookt at http://blackberry.github.io/Cascades-Samples/imageloader.html try to understand how he uses Q_PROPERTY(QVariant image READ image NOTIFY imageChanged) pass it in a model and set it as a qml context property and then load from qml.

Developer
Posts: 38
Registered: ‎09-27-2012
My Device: 9930
My Carrier: airtel

Re: Passing QByteArray image from c++ to QML

Thanks for your reply

 

So this is the only way to do ..?? It can be only done by passing the model from cpp other than passing the QByteArray..?

 

Developer
Posts: 44
Registered: ‎05-22-2013
My Device: Blackberry 10
My Carrier: 02

Re: Passing QByteArray image from c++ to QML

you can not pass QByteArray to QML you need to convert your bytearray to image data then bb::cascadeImage
Developer
Posts: 38
Registered: ‎09-27-2012
My Device: 9930
My Carrier: airtel

Re: Passing QByteArray image from c++ to QML

Thanks for your reply

 

Actually i converted it to an image and emitted through a signal from cpp.And when i am tring to set the image in a ImageView using setImage(), got an error : Unknown method parameter :Image.Its because eventhough i converted it to bb::cascades::Image.,in the QML it is getting as QVariant(bb::cascades::Image).

 

Developer
Posts: 38
Registered: ‎09-27-2012
My Device: 9930
My Carrier: airtel

Re: Passing QByteArray image from c++ to QML

Actually it was mistake from my side. I tried to set the image in QML using setImage() method. It is not the correct way.

The correct method is to use

id.image = imagefromcpp