title: TagLib - How to handle UTF-8 encoded file paths?
body: <p>Problem: I want TagLib::FileRef to open a file with Unicode characters in its file name or path, but do not succeed.</p>
  
  <p>I compiled TagLib 1.7 with MinGW (GNU Make 3.81, GCC 4.4.0) under Windows 7 (64-bit, but 32-bit compiler) after creating the Makefile with CMake 2.8.4. I use TagLib in conjunction with the Qt 4.7.2 framework.</p>
  
  <p>For interchanging strings between the two libraries, TagLib provides:</p>
  
  <pre><code>#define QStringToTString(s) TagLib::String(s.toUtf8().data(), TagLib::String::UTF8)
  #define TStringToQString(s) QString::fromUtf8(s.toCString(true))
  // toUtf8() is a fix, originally spelled utf8(), but that's not relevant here.
  </code></pre>
  
  <p>I constructed TagLib::FileRef as follows:</p>
  
  <pre><code>TagLib::FileRef fileRef( QStringToTString(filePath).toCString(true) );
  // or:
  TagLib::FileRef fileRef( TagLib::FileName( QStringToTString(filePath).toCString(true) ) );
  </code></pre>
  
  <p>As a result, files with paths containing Unicode characters or Latin-1 characters with a different code in the UTF-8 representation (f.ex. umlauts or chinese characters) fail to load (fileRef.isNull()).</p>
  
  <p>If I pass <em>false</em> to the function toCString() above (declaration: see below), TagLib can handle umlauts (but not Unicode-only characters). Therefore I guess I have compiled TagLib wrongly (TagLib::FileRef interpretes the given string as Latin-1), but I don't know how to check or even correct this. Note: Unicode strings in (ID3) tags are retrieved correctly with TagLib.</p>
  
  <p>toCString():</p>
  
  <pre><code>const char* TagLib::String::toCString( bool unicode = false ) const;
  </code></pre>
  
  <p>Doc: <a href="http://developer.kde.org/~wheeler/taglib/api/annotated.html" rel="nofollow">TagLib documentation</a></p>