Adding a TXXX frame to an ID3v2 tag

Scott Wheeler scott at
Wed Nov 14 18:44:20 GMT 2018

On 14/11/2018 19:35, Fred Gleason wrote:
> TagLib::MPEG::File *file=new TabLib::MPEG::File(“my_file.mp3”,false);
> TagLib::ID3v2::Tag *tag=(TagLib::ID3v2::Tag *)file->tag();

> [...] I suspect that my problem may be with the simplistic cast from 
> TagLib::Tag * to TabLib::ID3v2::Tag *

The problem is that the result of file->tag() *isn't* an ID3v2::Tag, so 
casting it to that fails.  (It's a special class that's a union of the 
available tag types for that file.)  To get the ID3v2 tag, you have to 
use the ID3v2Tag() method:

Also, in general, in C++, using C-style casts "(Foo *) p" isn't 
recommended -- you should use, generally, either dynamic_cast<Foo *>(p) 
(which does run-time type checking, and in this case would return 0), or 
static_cast<Foo *>(p) (which does some basic compile-time sanity checking).


More information about the taglib-devel mailing list