Qt Code:
To copy to clipboard, switch view to plain text mode
Qt Code:
To copy to clipboard, switch view to plain text mode
Save yourself some pain. Learn C++ before learning Qt.
Nop, this is not the case
fileName variable is a QString (not a ByteArray), i.e. fileName is Unicode (not a Local8Bit encoded)
The problem is that fileName QString is converted by QProcess to QByteArray (== char*)(as I suppose with using toLocal8Bit() method) and then passed it to the console application. But I'd like fileName to be converted to UTF-8
Did you try QString::toUtf8() ?
Save yourself some pain. Learn C++ before learning Qt.
I thought about
Qt Code:
exiflist_params << fileName.toUtf8();To copy to clipboard, switch view to plain text mode
but this is wrong since fileName.toUtf8() gives QByteArray which will be used for creating QString (costructor QString::QString ( const QByteArray & ba )) which will be inserted into exiflist_params. This cunstructror constructs QString assuming that QByteArray contains ASCII encoded data. This I think just like
Qt Code:
To copy to clipboard, switch view to plain text mode
It seems to be weird and does not work
On Mac OS X, QProcess uses UTF-8 for command line arguments. On Windows and Unix, it calls QString::toLocal8Bit(). If your file system uses UTF-8, just make sure your applications run the UTF-8 locale too (a good idea, in general). So fex, export LANG=en_US.UTF-8, and then launch your app. QProcess will then use UTF-8 for the arguments.
Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
Nokia Software Manager, Qt Development
I'm having the same issue - trying to write a German umlaut (ü) to QProcess but it doesn't work.
toLatin1() gets me "?", toUtf8() and toLocal8Bit() get me random symbols.
I didn't manage to understand from this thread how to address this. I'm running on Windows 7. Is there a way to set QProcess to handle UTF-8?
I do not think there is a way to change QProcess' behaviour, which unfortunately abstracts arguments as Unicode strings instead of plain NULL-terminated byte sequences. Here are two suggestions for working around the problem, in unspecified order of ugliness:
- Call QTextCodec::​setCodecForLocale() to set an UTF-8 codec, so that when QProcess calls QString::toLocal8Bit() to serialize the arguments, UTF-8 will be used. Unfortunately, this means changing an application-wide setting to solve a local issue.
- Preprocess the arguments before adding them to the QProcess' argument list: QString::fromLocal8Bit(fileName.toUtf8()). Something may get lost in translation.
Thank you for your reply!
After some thinking I figured I really could skip the whole cmd.exe usage and do something else. But I hope this thread is helpful to other users.
Bookmarks