I guess that's the correct fix to the existing QStringToTString() function.<br>But FileRef cannot take a TString object as an argument. So, I cannot use that function itself. <br><br>Instead, I'm using what is given in the function itself, i.e. s.toUtf8().data() which works perfectly as an argument to FileRef.<br>
<br>Thanks,<br>Plasty.<br><br><div class="gmail_quote">2009/12/6 Ιντζόγλου Θεόφιλος <span dir="ltr"><<a href="mailto:int.teo@gmail.com">int.teo@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I can't really remember where I got it from but I have the above lines in a<br>
header file:<br>
<br>
/*!<br>
* \relates TagLib::String<br>
*<br>
* Converts a TagLib::String to a QString without a requirement to link to Qt.<br>
*/<br>
#define Q4StringToTString(s) TagLib::String(s.toUtf8().data(),<br>
TagLib::String::UTF8)<br>
<br>
So all you need to use is Q4StringToTString(). It works just fine here. Hope ti<br>
helps!<br>
<br>
Theofilos Intzoglou<br>
<br>
Στις Κυριακή 06 Δεκεμβρίου 2009 12:39:37 Plasty Grove γράψατε:<br>
<div><div></div><div class="h5">> You're right about FileRef taking only const char *, and yes<br>
> QStringToTString doesn't help. But in addition, the function doesn't work.<br>
> I don't know if it's with the new qt libraries (I'm using 4.5.2). I took a<br>
> look at the macro definition for the function and it looks outdated. viz.<br>
><br>
> #define QStringToTString(s) TagLib::String(s.utf8().data(),<br>
> TagLib::String::UTF8)<br>
><br>
> QString no longer has a utf8() function.<br>
><br>
> But there is one thing I took away from this function that seems to work in<br>
> addition to toAscii() and that's toUtf8().data().<br>
><br>
> For some reason toUtf8().constData() doesn't work, but toUtf8().data()<br>
> works.<br>
><br>
> i.e.<br>
><br>
> TagLib::FileRef tagFile(qstr.toUtf8().data());<br>
><br>
> Would this be a more preferable way to do it than toAscii()?<br>
><br>
> Thanks,<br>
> Plasty.<br>
><br>
> PS: I also noticed that both Qt and taglib support utf16, but I tried it<br>
> and it didn't work and also I don't know much about UTF.<br>
><br>
><br>
> 2009/12/6 Lukáš Lalinský <<a href="mailto:lalinsky@gmail.com">lalinsky@gmail.com</a>><br>
><br>
> > On Sat, Dec 5, 2009 at 10:29 PM, Michael Pyne <<a href="mailto:mpyne@purinchu.net">mpyne@purinchu.net</a>> wrote:<br>
> > > On Saturday 05 December 2009 15:25:13 Plasty Grove wrote:<br>
> > >> That makes sense, but even the following doesn't work:<br>
> > >><br>
> > >> QString qstr = "/home/mydir/music/song.mp3";<br>
> > >> QByteArray qbArray = qstr.toLocal8Bit();<br>
> > >> const char* str = qbArray.constData();<br>
> > >> TagLib::FileRef tagFile(str);<br>
> > >><br>
> > >> In this case, I've got a local object which stores the value returned<br>
> > >> by toLocal8Bit() and which is in scope when I'm using str. Does<br>
> > >> qbArray get destroyed whenever constData() is called on it? When I'm<br>
> > >> debugging, I<br>
> ><br>
> > can<br>
> ><br>
> > >> still see str holding a value when it goes to the next step.<br>
> > ><br>
> > > Perhaps an encoding issue if you don't use straight US-ASCII for your<br>
> ><br>
> > file<br>
> ><br>
> > > names? In that case if "local8Bit" is not the encoding Taglib is<br>
> ><br>
> > expecting<br>
> ><br>
> > > you'll get weirdness.<br>
> > ><br>
> > > The KDE JuK music manager uses taglib and has TString/QString<br>
> > > conversion<br>
> ><br>
> > code<br>
> ><br>
> > > (and I'm sure Amarok has the same thing) if you want to see how those<br>
> ><br>
> > projects<br>
> ><br>
> > > do it.<br>
> ><br>
> > TagLib::String will not help in this case, because it also represents<br>
> > Unicode string, like QString. FileRef's filename parameter on<br>
> > non-Windows platforms is char*, so you need the actual encoded bytes.<br>
> > In Qt you can use QFile::encodeName(string) to encode the filename the<br>
> > same way Qt does it for file dialogs or other places that interact<br>
> > with the filesystem. This can still fail in some cases (different<br>
> > mounted filesystems using different encodings), but it's the best you<br>
> > can do if you store filenames as Unicode strings.<br>
> ><br>
> > --<br>
> > Lukas Lalinsky<br>
> > <a href="mailto:lalinsky@gmail.com">lalinsky@gmail.com</a><br>
> > _______________________________________________<br>
> > taglib-devel mailing list<br>
> > <a href="mailto:taglib-devel@kde.org">taglib-devel@kde.org</a><br>
> > <a href="https://mail.kde.org/mailman/listinfo/taglib-devel" target="_blank">https://mail.kde.org/mailman/listinfo/taglib-devel</a><br>
><br>
_______________________________________________<br>
taglib-devel mailing list<br>
<a href="mailto:taglib-devel@kde.org">taglib-devel@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/taglib-devel" target="_blank">https://mail.kde.org/mailman/listinfo/taglib-devel</a><br>
</div></div></blockquote></div><br>