Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, December 2006
How to convert java byte[] to a QByteArray without using String object ?


Message 1 in thread

Hello,

I start with a InputStream response (from web service) :

InputStream InputStream_ref = response.getInputStream();
byte[] data = new byte[InputStream_ref.available()];
InputStream_ref.read(data);

data contains a png image and I would like show it into QGraphicsPixmapItem
:

Create QByteArray, create QPixmap from QByteArray and set them into
QGraphicsPixmapItem.

Can I use QNativePointer ? How ? (casting fails from byte[] to
QNativePointer...)


Congratulation to the trolltech dev team for this fabulous set of tools,
thanks a lot!

FranÃois Weykmans

Message 2 in thread

FranÃois Weykmans wrote:

> byte[] data = new byte[InputStream_ref.available()];
> InputStream_ref.read(data);
>
> data contains a png image and I would like show it into 
> QGraphicsPixmapItem :
>
> Create QByteArray, create QPixmap from QByteArray and set them into 
> QGraphicsPixmapItem.
>
> Can I use QNativePointer ? How ? (casting fails from byte[] to 
> QNativePointer...)


In the next release of Jambi, QByteArray will have a constructor that 
takes an array of bytes directly, but in TP3 you will need to use 
QNativePointer, yes. Here's some example code (data is your array of bytes):


    QNativePointer np = new QNativePointer(QNativePointer.Type.Byte, 
data.length);
    for (int i=0; i<data.length; ++i) np.setByteAt(i, data[i]);
    QByteArray baData = new QByteArray(np, data.length);


Hope this helps!

-- Eskil