Problem using TagLib::FileRef under Windows with exotic filename

Tanguy Krotoff tkrotoff at gmail.com
Thu Nov 27 21:36:58 CET 2008


Did you try this macro ?

/** Converts a Qt4 QString to a TagLib::String. */
#define Qt4QStringToTString(s) TagLib::String(s.toUtf8().data(),
TagLib::String::UTF8)
there is also the TStringToQString macro

Use of these macros:
TagLib::String str(Qt4QStringToTString(fileName));
TagLib::FileRef fileRef(str.toCString());

TagLib::Tag * tag = fileRef.tag();
if (tag) {
	if (!tag->isEmpty()) {
		_title = TStringToQString(tag->title()).trimmed();
		...


I think it is the "official" way to deal with UTF8, TagLib and Qt4
(I found theses macros somewhere inside TagLib source code)

On Thu, Nov 27, 2008 at 5:37 PM, Joel Lopes Da Silva
<joel at lopes-da-silva.com> wrote:
> Hello,
>
> Sorry about this silly question but I tried many many things to get a
> small C++ function to open an MP3 file with TagLib under Windows, and
> yet, I can't get it to work with exotic filenames (such as Japanese
> filenames).
>
> Here is basically what I did:
>
> string utf8 = "C:\\path\\to\\audioFileWithJapaneseFilename.mp3";
> int charcount = MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1,
> NULL, 0);
> wchar_t* buf = new wchar_t[charcount];
> MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1, buf, charcount);
> TagLib::FileRef f(buf);
>
> I generated a Visual Studio 2008 project with Cmake and the sources of
> TagLib, and I modified the main function of tagreader.cpp to put this
> code within the main function (and I removed the "for" loop). And I am
> sure my tagreader.cpp file is encoded in UTF-8.
>
> Under Mac OS X and Linux, my problem is already solved thanks to
> QFile::encodeName, but I really can't get this small piece of code to
> work under Windows. And I accept to use almost any solution: using
> some special function of Qt, or using MultiByteToWideChar, or anything
> else.
>
> Thank you very much in advance.
>
> --
> Joel Lopes Da Silva
>
>
>
> _______________________________________________
> taglib-devel mailing list
> taglib-devel at kde.org
> https://mail.kde.org/mailman/listinfo/taglib-devel
>



-- 
Tanguy Krotoff <tkrotoff at gmail.com>
+33 6 68 42 70 24


More information about the taglib-devel mailing list