开发者

Using QBuffer for binary data

I am writing a Qt (4.6) application t开发者_JS百科hat is responsible for reading from a usb acm modem device. A mix of raw binary and (ascii) character data is read in from the device. I have a thread that is responsible for constantly reading data from the device into shared memory as it becomes available and second thread that handles processing of this data.

I was thinking of using the QBuffer class as a means to store the data and share it between threads but as I read about QByteArray (which QBuffer uses as a data store). I became worried that the QBuffer will always be appending a '\0' Null character to the end of the data that is being passed between threads since QByteArray exhibits this behavior? Is this the case or will QBuffer allow me to store and retrieve data without enforcing any terminating '\0' character on all of my data?


The terminating 0 is transparent to your application.

For instance, if you append "ABC" to an array, "ABC\0" will be appended, but size() will still return 3 and if you subsequently append "DEF" the array will contain "ABCDEF\0" (and size() will still return 6, not 7).

The terminating 0 may be useful in case you request the pointer to the raw data for further processing using functions from the C library.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜