0
我正在使用Taglib并将封面艺术写入mp3。这里下面的代码工作:删除或智能指针失败
bool MediaHelper::AddCoverArt(const QString &media, const QString &image_file)
{
TagLib::MPEG::File mpeg(media.toStdString().c_str());
TagLib::ID3v2::Tag *id3v2Tag = mpeg.ID3v2Tag(true);
TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame;
frame->setMimeType("image/jpeg");
frame->setPicture(image.data());
id3v2Tag->addFrame(frame);
mpeg.save();
delete frame;
return true;
}
但一旦我离开函数读取访问冲突应用程序崩溃
我然后用QScopedPointer试了一下:
bool MediaHelper::AddCoverArt(const QString &media, const QString &image_file)
{
TagLib::ID3v2::Tag *id3v2Tag = mpeg.ID3v2Tag(true);
QScopedPointer<TagLib::ID3v2::AttachedPictureFrame> frame(new TagLib::ID3v2::AttachedPictureFrame);
frame->setMimeType("image/jpeg");
frame->setPicture(image.data());
id3v2Tag->addFrame(frame.data());
mpeg.save();
return true;
}
但同样的事情发生时,我离开了这个功能。我有点难过,因为如果我没有照顾删除框架,那么我将为自己创造一个大问题。如果任何人都可以给我一些见解。
谢谢我看了文档说明,但不是功能。谢谢你帮我清理它 – adviner