i was trying to say the same thing... ummm.. my english..
i was trying to say the same thing... ummm.. my english..
Then why QString class have this function.
Qt Code:
To copy to clipboard, switch view to plain text mode
This function takes char* parameter and function name says fromUtf8. Does it mean Qt accepting Utf8 formatted string pointed by char*.
So it implies Qt itself saying that a Utf8 formatted string can be pointed by char*.
go and read wikipedia
UTF-8 encodes each character (code point) in 1 to 4 octets (8-bit bytes), with the single octet encoding used only for the 128 US-ASCII characters. See the Description section below for details.
"const char *" in C/C++ is "an array of 8bit values" so anything can go there. Its Qt equivalent is QByteArray. How the data stored in a particular const char * is interpreted is another story (that's why you have the "size" parameter here). UTF-8 strings CAN contain 0x00 values - but only if you directly place them there yourself. So in 99.9% of the cases keeping a utf-8 string in a C byte array without also keeping its size is fine.
Other way to go around is serialization. He write the software he know what he can expect. For example the integer may vary on differend CPU's and OSes but thats why Qt provide to us qint8, qint16, qint32, qint64. In this way we can guarantee that the size of bytes will be fixed. So lets say that even he do not have 0x00 on the end of the utf-8 string, he can use other methods around. For example his own protocol, lets say he knows that the first 2 bytes that come are the length of the string, then he will know how much to continue to read further. I know that you are aware of this, I just point it out to make the thing clear( and a bit offtopic ).
Ontopic: By my opinion the function in the API that yangyunzhao is talking about does not recognize utf-8.
buhuhuhuhu... this thread has killed all my reputation
![]()
Bookmarks