[prev in list] [next in list] [prev in thread] [next in thread]
List: taglib-devel
Subject: Re: Creating FileRef object from QString
From: Michael Pyne <mpyne () purinchu ! net>
Date: 2009-12-05 19:48:05
Message-ID: 200912051448.05539.mpyne () purinchu ! net
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
On Saturday 05 December 2009 13:59:35 Plasty Grove wrote:
> Hi,
>
> I'm developing using qt and have a situation where I have to create a
> FileRef object from a QString object.
>
> --------------------------------------------------
> TagLib::FileRef tagFile("/home/mydir/music/song.mp3") //---> Works fine
> --------------------------------------------------
> QString qstr = "/home/mydir/music/song.mp3";
> const char* str = qstr.toLocal8Bit().constData();
> TagLib::FileRef tagFile(str); //---> Doesn't work, shows as empty in
> debugger and segfaults when I try to access
> --------------------------------------------------
>
> What am I doing wrong here?
QString::toLocal8Bit returns a QByteArray, not a const char *.
That QByteArray is destructed once .constData() returns (since there's no
reason for C++ to keep it around).
So now your const char * pointer is dangling in the middle of freed memory,
and you get a crash.
Regards,
- Michael Pyne
["signature.asc" (application/pgp-signature)]
_______________________________________________
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