reading utf8 as data stream.
Hi,
Flash 10, action script 4 sends strings this way:
int16 describing size
then char * data.
To my knowledge, this type of string is not serialized in QT.
so i made this class:
Code:
{
public:
QString ReadUTF8
(qint16 maxsize
= 4096) {
Q_ASSERT(maxsize <= 4096);
static char buffer[4096];
qint16 stringlength;
(*this) >> stringlength;
if (stringlength < maxsize)
{
readRawData(&buffer[0] , stringlength);
}
return QString::fromAscii(buffer, stringlength
);
}
{
(*this) << data.size();
writeRawData((char*)data.data(), data.size());
}
Now, my question is; There has got to be a better way of reading the string than having to copy those bytes twice. Is there a way to achieve what i am doing in one operation?
Re: reading utf8 as data stream.
You could read the length and then use QTextStream.
Why do you use fromAscii() if you want to read UTF-8?