TagLib::FileRef and Unicode

Jeremy Gregorio jeremy.firefox.addon at gmail.com
Mon Dec 2 13:42:33 UTC 2013

Hi all,
      I finally noticed my little tagging program doesn't handle Unicode in
the slightest :).

      Does anyone have suggestions on handling Unicode files?

      I'm on an English (United States) Windows XP install trying to build
with Visual C++.

      To deal with the headache that is passing Unicode Parameters I use
URI Encoding (like here http://meyerweb.com/eric/tools/dencoder/) to encode
the parameters to a command line program I wrote and then decode them as
they come in. This part seems to work since I can decode the strings and
write them to tags with the Unicode intact.

      But when I try to write tags to a file on a Unicode path it fails :(.
Right no I'm using QT's library to handle the strings because of a
stackoverflow post I found where the guy had good luck with it, but darned
if I can get it working.

int main(int argc, char *argv[])

    TagLib::List<TagLib::FileRef> fileList;

    std::string fileName( "c:\\temp\\debug " );
    std::string extension (".txt");
    ofstream a_file ( fileName + extension );

    QString filepath ( argv[argc - 1] );

    QString url = QUrl::fromPercentEncoding( filepath.toUtf8() );

    a_file << "Param: " << url.toStdString()  << "\n\n";

    QFile myQfile ( url );

    if( !myQfile.exists() ){
        a_file << "The param \""  << myQfile.error() << "\" is not a file.";
    }//END IF

    TagLib::FileRef f( QFile::encodeName(url).constData() );

    if(!f.isNull() && f.tag())



  //... If I get this far I can start applying tags.

 The above works great until I try it with a unicode path, like

"C:\temp\?\Power Up!.mp3"

which I encode as


I know I'm at least getting the string decoded right since I write it to a
text file and it looks right in notepad++ encoded in UTF-8 without the BOM.

Jeremy D Gregorio

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/taglib-devel/attachments/20131202/1d437d55/attachment.html>

More information about the taglib-devel mailing list