[Qt-interest] Non-Ascii filenames with QFile
Santosh Puranik
santosh.puranik at nokia.com
Wed Feb 10 15:57:05 CET 2010
Hello,
I am having this problem with creating files with non-ascii characters
in the filepath using QFile...
int main(int argc, char** argv)
{
QFile f("/home/user/áèîõü.mp3");
f.open(QIODevice::ReadWrite);
f.close();
}
This works fine. Now when I create a QCoreApplication (our real
application is a QCoreApplication)
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
QFile f("/home/user/áèîõü.mp3");
f.open(QIODevice::ReadWrite);
f.close();
}
this fails --> Instead of "áèîõü.mp3", I now have a file ".mp3" created.
Some investigation suggests that creating a QCoreApplication modifies
the QTextCodec, and QFile internally calls QString::toLocal8Bit() on the
filepath ... which removes all those non-ascii characters.
Some investigation showed that creating a QCoreApplication sets a global
named qt_locale_initialized, and QString::toLocal8Bit() then checks on
this global to decide whether to use iconv (I am running this on Linux),
or Latin1 decoding. The decoding to local8Bit() depends on the system's
locale. (In my case it was POSIX, and locale charmap was ANSI_X3.4-1968).
My question then is:
Why should QFile have to encode the file path to local8Bit() encoding? I
guess it is to achieve platform compatibility. So could there be an API
in QFile where I can specify the encoding of the file path, so that it
does not try to encode it again?
Best Regards,
Santosh
More information about the Qt-interest-old
mailing list