PDA

View Full Version : Checking QByteArray



camol
17th March 2011, 22:00
I have one question is possible some how to check what kind of data type the QByteArray buffer is carring? I am expecting three types: QStringList, QString,, and the exact date which i will write to the file? I tried using QByteArray::contains("STORAGE"), becouse I know that if it will be QStringList, each QString in that QStringList will have "STORAGE" somewhere. But this is not actually working.When i do contains("S") it sees the single char but only one at time.

squidge
17th March 2011, 23:26
QByteArray, as its name suggests, contains an array of bytes. It doesn't care about what the data is or how its formatted. It's just a sequence of raw, unformatted bytes.

What are you actually trying to do?

camol
18th March 2011, 10:02
When client connects to the server the client firstly receives QStringList from server, then it sends many files one by one. I want to do this like this:client doesn't know what he will get, he only by checking the QByteArray he received he should know what to do.

squidge
18th March 2011, 14:07
Right, so you need to develop a protocol which supports what you want to do.

For example, the http protocol sends the text string "Content-length" so that clients know the amount of data to expect, and strings such as "Content-Disposition: attachment; filename='filename.ext'". So the client knows a default filename before asking the user if they wish to rename it.

Once you had sent the data for all files, you can begin data transfer of the files. Its a good idea to use a synchronisation (expected sequence of bytes) so the client knows they have received each file correctly.