PDA

View Full Version : QFile error string is returned in wrong language



Henning
8th March 2018, 10:14
Hello,

I have an issue with the language used in a string returned from QFile errorString().
The error is returned in the language defined from system (Windows), but I need to display this message in my application always in english.
Setting default QLocale doesn't seem to have any effect:



// Set language to a different language as defined in QLocale::system()
QLocale::setDefault(QLocale("en_US"));
QFile file("");
file.open(QFile::ReadOnly);
// Error string still in system language
const QString errorString = file.errorString();


Is there a way to change language used from QFile errorString() or a way to use an existing parser to parse QFile::FileError to a specified language?

ChristianEhrlicher
8th March 2018, 18:07
You can use http://doc.qt.io/qt-5/qfiledevice.html#error . errorString() is getting it's string from Windows and therefore the Windows locale is used

Henning
9th March 2018, 10:20
Yes I know how to get the error code from QFile but I found no parser to parse this error code into a readable string. I don't want to write a parser, when a parser seems to exist somewhere.

Is there a way to use the parser who is used internaly from QFile class with a specified language?