[Qt-interest] QFileInfoList and UTF-8
Niels Dekker (Qt-interest)
mymailfromqt at xs4all.nl
Thu Feb 24 13:32:48 CET 2011
Nikos Chantziaras wrote:
> Mathieu Malaterre wrote:
>> I am trying to use QDir, but I do not understand how I should be
>> dealing with UTF-8 encoded filename. Here is a simple demo that I
>> tried on my linux box:
>>
>> $ mkdir /tmp/demo
>> $ touch /tmp/demo/François.txt
>> $ ./demo /tmp/demo
>> /tmp/demo/François.txt
>> $ echo $LANG
>> en_US.utf8
>>
>> Here is the code for demo.cxx:
>>
>> #include<QDir>
>> #include<QString>
>> #include<iostream> // std::cout
>>
>> int main(int , char *argv[])
>> {
>> const char *dirname = argv[1];
>> QDir dir( QString::fromUtf8(dirname) );
>> QFileInfoList children =
>> dir.entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot);
>> QFileInfo file = children.at(0);
>> std::cout<< file.absoluteFilePath().toUtf8().constData()<<
>> std::endl;
>>
>> return 0;
>> }
> You can't assume the local filesystem uses UTF-8.
??? Given the fact that "echo $LANG" returns en_US.utf8 on Mathieu's
machine, why can't he assume the local filesystem uses UTF-8?
Thanks in advance,
Niels
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center
More information about the Qt-interest-old
mailing list