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

Qt-interest Archive, July 2007
QByteArray from unsigned char*


Message 1 in thread

Hello,

I have an array of unsigned char and now I want to store this data into 
QByteArray to be able to store the data into a file (including all  '\0's).

Now I haven't found any solution to to so (storing unsigned char* into a 
file with Qt).

Can anyone tell me how to solve my problem?

Regards,
Patrick 


--
 [ signature omitted ] 

Message 2 in thread

What's wrong with QByteArray::fromRawData(const char * data, int size) 
????
You receive a QByteArray from this static method which you can 
conviniently write to files (i.e. using QDataStream or QFile directly ...)

Regards,
Malte

--
 [ signature omitted ] 

Message 3 in thread

The problem is that I get an "unsigned char*" and QByteArray::fromRawData 
needs a "const char*", so I need to cast "unsigned char*" to "const char*" 
and QByteArray::fromRawData stops at the first '\0' of the data.

Regards,
Patrick

"Malte Witt" <malte.witt@xxxxxxxxxxxxx> schrieb im Newsbeitrag 
news:OF6279E251.B288E3A2-ONC125730C.00367463-C125730C.00369E05@xxxxxxxxxxxxxxxx
> What's wrong with QByteArray::fromRawData(const char * data, int size)
> ????
> You receive a QByteArray from this static method which you can
> conviniently write to files (i.e. using QDataStream or QFile directly ...)
>
> Regards,
> Malte
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/ 


--
 [ signature omitted ] 

Message 4 in thread

> The problem is that I get an "unsigned char*" and 
QByteArray::fromRawData 
> needs a "const char*", so I need to cast "unsigned char*" to "const 
char*" 
Yes, but how could this be a problem if you want to write the contents to 
a file? If you access the QByteArray by the data() method, it will get 
deepcopied and you can access the copy in a NON-const way ...
Conversion from unsigend to signed doesn't matter at all if you just want 
to write the data to a file ...


> and QByteArray::fromRawData stops at the first '\0' of the data.
No - AFAIK it does not ...

Regards,
Malte


--
 [ signature omitted ] 

Message 5 in thread

What Qt version are you using?

the doc for Qt 4.3 explicitely states that it should work on data that
has \0 embedded (see the example).

http://doc.trolltech.com/4.3/qbytearray.html#fromRawData

Cheers,
Peter

> -----Original Message-----
> The problem is that I get an "unsigned char*" and
QByteArray::fromRawData
> needs a "const char*", so I need to cast "unsigned char*" to "const
char*"
> and QByteArray::fromRawData stops at the first '\0' of the data.
> 
> Regards,
> Patrick

--
 [ signature omitted ] 

Message 6 in thread

"Patrick Feistel" <Feistel@xxxxxxxxxx> wrote in message 
news:f6aifh$nq$1@xxxxxxxxxxxxxxxxxxxxx
> The problem is that I get an "unsigned char*" and 
> QByteArray::fromRawData needs a "const char*", so I need to cast 
> "unsigned char*" to "const char*" and QByteArray::fromRawData stops at 
> the first '\0' of the data.

That's where the second parameter "size" comes in.

Volker


--
 [ signature omitted ]