[prev in list] [next in list] [prev in thread] [next in thread] 

List:       taglib-devel
Subject:    Re: Creating FileRef object from QString
From:       Plasty Grove <plasty.grove () gmail ! com>
Date:       2009-12-06 11:20:15
Message-ID: eb2963f20912060308l6ba922e4t4cc7dcd3affce51d () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I guess that's the correct fix to the existing QStringToTString() function.
But FileRef cannot take a TString object as an argument. So, I cannot use
that function itself.

Instead, I'm using what is given in the function itself, i.e.
s.toUtf8().data() which works perfectly as an argument to FileRef.

Thanks,
Plasty.

2009/12/6 Ιντζόγλου Θεόφιλος <int.teo@gmail.com>

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

[Attachment #5 (text/html)]

I guess that&#39;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&#39;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">&lt;<a \
href="mailto:int.teo@gmail.com">int.teo@gmail.com</a>&gt;</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&#39;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">&gt; You&#39;re right about \
FileRef taking only const char *, and yes<br> &gt; QStringToTString doesn&#39;t help. \
But in addition, the function doesn&#39;t work.<br> &gt;   I don&#39;t know if \
it&#39;s with the new qt libraries (I&#39;m using 4.5.2). I took a<br> &gt;   look at \
the macro definition for the function and it looks outdated. viz.<br> &gt;<br>
&gt; #define QStringToTString(s) TagLib::String(s.utf8().data(),<br>
&gt; TagLib::String::UTF8)<br>
&gt;<br>
&gt; QString no longer has a utf8() function.<br>
&gt;<br>
&gt; But there is one thing I took away from this function that seems to work in<br>
&gt; addition to toAscii() and that&#39;s toUtf8().data().<br>
&gt;<br>
&gt; For some reason toUtf8().constData() doesn&#39;t work, but toUtf8().data()<br>
&gt; works.<br>
&gt;<br>
&gt; i.e.<br>
&gt;<br>
&gt; TagLib::FileRef tagFile(qstr.toUtf8().data());<br>
&gt;<br>
&gt; Would this be a more preferable way to do it than toAscii()?<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Plasty.<br>
&gt;<br>
&gt; PS: I also noticed that both Qt and taglib support utf16, but I tried it<br>
&gt;   and it didn&#39;t work and also I don&#39;t know much about UTF.<br>
&gt;<br>
&gt;<br>
&gt; 2009/12/6 Lukáš Lalinský &lt;<a \
href="mailto:lalinsky@gmail.com">lalinsky@gmail.com</a>&gt;<br> &gt;<br>
&gt; &gt; On Sat, Dec 5, 2009 at 10:29 PM, Michael Pyne &lt;<a \
href="mailto:mpyne@purinchu.net">mpyne@purinchu.net</a>&gt; wrote:<br> &gt; &gt; &gt; \
On Saturday 05 December 2009 15:25:13 Plasty Grove wrote:<br> &gt; &gt; &gt;&gt; That \
makes sense, but even the following doesn&#39;t work:<br> &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt; QString qstr = &quot;/home/mydir/music/song.mp3&quot;;<br>
&gt; &gt; &gt;&gt; QByteArray qbArray = qstr.toLocal8Bit();<br>
&gt; &gt; &gt;&gt; const char* str = qbArray.constData();<br>
&gt; &gt; &gt;&gt; TagLib::FileRef tagFile(str);<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt; In this case, I&#39;ve got a local object which stores the value \
returned<br> &gt; &gt; &gt;&gt; by toLocal8Bit() and which is in scope when I&#39;m \
using str. Does<br> &gt; &gt; &gt;&gt; qbArray get destroyed whenever constData() is \
called on it? When I&#39;m<br> &gt; &gt; &gt;&gt; debugging, I<br>
&gt; &gt;<br>
&gt; &gt; can<br>
&gt; &gt;<br>
&gt; &gt; &gt;&gt; still see str holding a value when it goes to the next step.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Perhaps an encoding issue if you don&#39;t use straight US-ASCII for \
your<br> &gt; &gt;<br>
&gt; &gt; file<br>
&gt; &gt;<br>
&gt; &gt; &gt; names? In that case if &quot;local8Bit&quot; is not the encoding \
Taglib is<br> &gt; &gt;<br>
&gt; &gt; expecting<br>
&gt; &gt;<br>
&gt; &gt; &gt; you&#39;ll get weirdness.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; The KDE JuK music manager uses taglib and has TString/QString<br>
&gt; &gt; &gt; conversion<br>
&gt; &gt;<br>
&gt; &gt; code<br>
&gt; &gt;<br>
&gt; &gt; &gt; (and I&#39;m sure Amarok has the same thing) if you want to see how \
those<br> &gt; &gt;<br>
&gt; &gt; projects<br>
&gt; &gt;<br>
&gt; &gt; &gt; do it.<br>
&gt; &gt;<br>
&gt; &gt; TagLib::String will not help in this case, because it also represents<br>
&gt; &gt; Unicode string, like QString. FileRef&#39;s filename parameter on<br>
&gt; &gt; non-Windows platforms is char*, so you need the actual encoded bytes.<br>
&gt; &gt; In Qt you can use QFile::encodeName(string) to encode the filename the<br>
&gt; &gt; same way Qt does it for file dialogs or other places that interact<br>
&gt; &gt; with the filesystem. This can still fail in some cases (different<br>
&gt; &gt; mounted filesystems using different encodings), but it&#39;s the best \
you<br> &gt; &gt; can do if you store filenames as Unicode strings.<br>
&gt; &gt;<br>
&gt; &gt; --<br>
&gt; &gt; Lukas Lalinsky<br>
&gt; &gt; <a href="mailto:lalinsky@gmail.com">lalinsky@gmail.com</a><br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; taglib-devel mailing list<br>
&gt; &gt; <a href="mailto:taglib-devel@kde.org">taglib-devel@kde.org</a><br>
&gt; &gt; <a href="https://mail.kde.org/mailman/listinfo/taglib-devel" \
target="_blank">https://mail.kde.org/mailman/listinfo/taglib-devel</a><br> &gt;<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>



_______________________________________________
taglib-devel mailing list
taglib-devel@kde.org
https://mail.kde.org/mailman/listinfo/taglib-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic