QStrings are Unicode strings. You can't create a QString that uses ISO-8859-1 encoding. If you want to use a certain encoding, you will have to switch to QByteArray.
How do you send that string?
QStrings are Unicode strings. You can't create a QString that uses ISO-8859-1 encoding. If you want to use a certain encoding, you will have to switch to QByteArray.
How do you send that string?
i'm sending it through a simple tcp socket connection...
to convert it i have to put my string into a QByteArray and send it?
Can't i just have a QString with the text converted in ?
thx
If you use only QTcpSocket, you need QByteArray anyway. Try QString::toLatin1() or QString::toLocal8Bit().
No, because QString isn't an array of bytes, but an array of QChars and QChars are Unicode characters.
Jacek, the conversion to the local locale works only if both, the server and the client, use the same Locale.
I really wonder why Mattia receives junk. A TCP connection does not change byte values because it would not know how to do it. Mattia, could you please post a small example for the server/client which reproduces the problem without your latin1() conversion? The problem lies perhaps elsewhere.
There are 10 people in the world. Those who understand binary and those who don't.
You can use QString::toLatin1(), if the receiver expects ISO-8859-1 string. If your protocol is text-based, you can use QTextStream and set the encoding using QTextStream::setCodec().
I'm still here trying to fix this problem...
I receive strange char...maybe does the socket do an ASCII 7bit conversion?Qt Code:
QTcpSocket socket; inSendMessage << string.toLatin1() << endl;To copy to clipboard, switch view to plain text mode
The server is developed with Qt3...maybe there is a charset encoding problem between them?
Last edited by mattia; 16th January 2008 at 11:26.
Are you sure you create that QString properly? What encoding do you use for "èèèèèè"?
to know what codec i'm using have i to use QTextCodec::codecForCStrings() ?
but it's return a *QTextCodec ... isn't there a sort of toString() method to print the codec name?
You can try QTextCode::name() or QTextCodec::aliases(), but better simply set the right codec using QTextCodec::setCodecForCStrings().
Bookmarks