Seems to be an encoding issue.
Are you running linux?
What settings are your relevant environment variables (LANG, LC_xxxx etc)?
What locale is Qt set to?
Seems to be an encoding issue.
Are you running linux?
What settings are your relevant environment variables (LANG, LC_xxxx etc)?
What locale is Qt set to?
Yes, it seems to be an encoding issue. I am using Linux with Qt 4.4.
I found the problem in my code. I was using toUtf8() function to get the copy the string from QString to another QString. So, this is the existing code:
Qt Code:
To copy to clipboard, switch view to plain text mode
Now, if i change the above code to:
Qt Code:
To copy to clipboard, switch view to plain text mode
It works properly.
I have one simple query:
trUtf8() is supposed to take "char *" argument and return a QString but here i am giving it a QString as argument. Is it ok to do so?
My GNU/Linux Blog:
http://funwithlinux.blogspot.com
Wasn't trUtf8() introduced with Qt4.5?
I don't quite see why you don't just copy it by assigning (assuming qsOriginalStr is really a meaningful QString and not just some byte array that was wrongly de/encoded.)
This code will produce a QByteArray with the UTF-8 encoding of your string. Those bytes will then (by the default encoding, whatever that might be in your case) converted back into a string. Quite plausible that this will not get you what you want.Qt Code:
To copy to clipboard, switch view to plain text mode
To be honest, I don't see how that should compile either.Qt Code:
To copy to clipboard, switch view to plain text mode
Looking at the sources trUtf8 wants a char* (no overloads for QString; at least not in 4.5.0; and also no implicit QString -> char* casts.)
HTH
trUtf8() is in Qt 4.4 too. If i assign qsOriginalStr directly, it gives me junk characters, so i have to use trUtf8() to get the proper encoded string.
This was the existing code which wasn't written by me.
I don't get any compilation errors so i think it implicitly converts the QString to char *
Should i do like this:
Qt Code:
To copy to clipboard, switch view to plain text mode
My GNU/Linux Blog:
http://funwithlinux.blogspot.com
well, it does not really make sense to convert a string into the Latin1 encoding and then tell trUtf8 to pretend that this really is UTF8 encoded data...Qt Code:
To copy to clipboard, switch view to plain text mode
The original "string" should be either not a QString but only a QByteArray, or it should already be (as QStrings are) a unicode encoded string and no conversions should be needed.
Where does qsOriginalStr come from?
qsOriginalStr comes from mysql database. Here's the code:
Qt Code:
MYSQL_ROW queryRow; int queryFields = mysql_num_fields(pQueryResult); while( (queryRow = mysql_fetch_row(pQueryResult)) != NULL ) { printf("cSqlClient::cSqlQuery:next row\n"); for( i=0; i < queryFields; i++ ) {To copy to clipboard, switch view to plain text mode
This is the existing written by someone else. I think i can just replacebyQt Code:
To copy to clipboard, switch view to plain text modeand use trUtf8 directly on the (char *)Qt Code:
qsOriginalStr = (char *)(queryRow[i]);To copy to clipboard, switch view to plain text mode
My GNU/Linux Blog:
http://funwithlinux.blogspot.com
Bookmarks