Issues with unicode conversion

Scott Wheeler wheeler at
Fri Aug 17 13:54:20 CEST 2007

Ali Shah wrote:
> Hi, I have some weird issues with trying to retrieve tags in unicode,
> while using taglib 1.4.
> I am trying to retrieve the album name, the track title and the artist
> (in this specific order)
> from a tag in utf-8 format. Unfortunately if I extract the tag like the
> example below, the title sanity check's end up being garbage for some
> tracks, and perfect for others. For example the current setup seems to
> work with UTF-8 tags, where as they fail for normal ascii Tags..
> What am i doing wrong? I've been trying to work out the issues all
> nigth and I am completely at a loss. 
> /*** Copy the album */
>     const char* actualAlbum =
>     tagFile.tag()->album().to8Bit(true).c_str();
>     if (tagFile.tag()->album() == TagLib::String(""))
>     {
>         actualAlbum= unknownString.toCString(true);
>     }
>     char* album = strdup(actualAlbum); 
>     QString qalbum1 = QString::fromUtf8(actualAlbum);
>     QString qalbum2 = QString::fromUtf8(album);
>     qDebug() << "Album sanity check1: " << qalbum1;
>     qDebug() << "Album sanity check2: " << qalbum2; 

This doesn't actually have anything to do with unicode -- you're using 
the c_str() function on a temporary value and then saving it for later, 
but once the "parent" string has passed out of scope (the end of the 
function call) the c_str() is no longer valid.

But it'd probably be easier to just use the TStringToQString() macro 
provided in the tstring.h header (or a slightly modified one for Qt 4).  :-)


More information about the taglib-devel mailing list