[Qt-interest] QFileInfoList and UTF-8

Thiago Macieira thiago at kde.org
Thu Feb 24 14:59:18 CET 2011


Em quinta-feira, 24 de fevereiro de 2011, às 13:04:01, Mathieu Malaterre 
escreveu:
> Dear all,
> 
>   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:

You don't have to do anything. The properly-encoded filenames are automatically 
decoded in Qt.

This, of course, assumes that you wrote a proper application. Unfortunately, 
yours contains a small but important mistake:

> 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;
> }
> 
> What am I missing from the call to entryInfoList ? I am trying to use
> a 3rd party library which expect filenames to be specified as UTF-8.

You're missing a QCoreApplication.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110224/38ed26b4/attachment.bin 


More information about the Qt-interest-old mailing list