首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TagLib:无法打开文件

TagLib:无法打开文件
EN

Stack Overflow用户
提问于 2012-05-14 15:55:59
回答 1查看 2.1K关注 0票数 1

我正在尝试编写一个简单的程序来了解TagLib (http://developer.kde.org/~wheeler/taglib.html)是如何工作的。该程序可以很好地处理代码中的注释。但是当我更改代码时,我得到了这些我无法解决的错误。以下是代码

代码语言:javascript
复制
#include<iostream>
#include<QString>
//#include "Helper.h"
#include "../../player/Util.h"
#include <taglib/tag.h>
#include <taglib/taglib.h>
#include <taglib/fileref.h>
#include <QString>


#include <boost/filesystem.hpp>

using std::string;
struct MetaData{

    string filepath, artist, album, title;
    signed int year, track_num, length_ms, bitrate;
};

//MetaData getMetaDataOfFile(QString file)
MetaData getMetaDataOfFile(string file)
{
    MetaData md;
    //TagLib::FileRef f(TagLib::FileName(file.toUtf8())); 
    const char * filename = file.c_str();
    std::cout<< filename;
    TagLib::FileRef f(TagLib::FileName(filename)); 

    //md.filepath = file.toStdString();
    md.filepath = file;

    //boost::filesystem::path filePath(file.toStdString());
    boost::filesystem::path filePath(file);
    md.title = filePath.stem().string();

    if(f.isNull()) return md;
    if(!f.tag()) return md;
    if(f.tag()->isEmpty()) return md;

    string artist = f.tag()->artist().to8Bit(true);
    string album = f.tag()->album().to8Bit(true);
    string title = f.tag()->title().to8Bit(true);
    uint year = f.tag()->year();
    uint track = f.tag()->track();
    int bitrate = f.audioProperties()->bitrate() * 1000;
    int length = f.audioProperties()->length();

    md.album = cnvrtString2FirstUpper(album);
    md.artist = cnvrtString2FirstUpper(artist);
    md.title = cnvrtString2FirstUpper(title);
    //md.filepath = file.toStdString();
    md.filepath = file;
    md.length_ms = length * 1000;
    md.year = year;
    md.track_num = track;
    md.bitrate = bitrate;

    if(md.title.length()==0)
    {

    //boost::filesystem::path filePath(file.toStdString());
    boost::filesystem::path filePath(file);
    md.title = filePath.stem().string();
    }

    return md;
}






int main()
{
    using namespace std;



    //QString file("/home/vickey/Downloads/song1.mp3");
    string file("/home/vickey/Downloads/song1.mp3");
    MetaData md = getMetaDataOfFile(file);

    return 0;

}

在编译时,我得到这个错误

代码语言:javascript
复制
 g++ getmd.cpp -o getmd -I /usr/include/qt4/ -I /usr/include/qt4/QtCore/ -ltag -lboost_system -lboost_filesystem -lQtCore -g
getmd.cpp: In function ‘MetaData getMetaDataOfFile(std::string)’:
getmd.cpp:36:10: error: request for member ‘isNull’ in ‘f’, which is of non-class type ‘TagLib::FileRef(TagLib::FileName) {aka TagLib::FileRef(const char*)}’
getmd.cpp:37:11: error: request for member ‘tag’ in ‘f’, which is of non-class type ‘TagLib::FileRef(TagLib::FileName) {aka TagLib::FileRef(const char*)}’
getmd.cpp:38:10: error: request for member ‘tag’ in ‘f’, which is of non-class type ‘TagLib::FileRef(TagLib::FileName) {aka TagLib::FileRef(const char*)}’
getmd.cpp:40:23: error: request for member ‘tag’ in ‘f’, which is of non-class type ‘TagLib::FileRef(TagLib::FileName) {aka TagLib::FileRef(const char*)}’
getmd.cpp:41:22: error: request for member ‘tag’ in ‘f’, which is of non-class type ‘TagLib::FileRef(TagLib::FileName) {aka TagLib::FileRef(const char*)}’
getmd.cpp:42:22: error: request for member ‘tag’ in ‘f’, which is of non-class type ‘TagLib::FileRef(TagLib::FileName) {aka TagLib::FileRef(const char*)}’
getmd.cpp:43:19: error: request for member ‘tag’ in ‘f’, which is of non-class type ‘TagLib::FileRef(TagLib::FileName) {aka TagLib::FileRef(const char*)}’
g    etmd.cpp:44:20: error: request for member ‘tag’ in ‘f’, which is of non-class type ‘TagLib::FileRef(TagLib::FileName) {aka TagLib::FileRef(const char*)}’
getmd.cpp:45:21: error: request for member ‘audioProperties’ in ‘f’, which is of non-class type ‘TagLib::FileRef(TagLib::FileName) {aka TagLib::FileRef(const char*)}’
getmd.cpp:46:20: error: request for member ‘audioProperties’ in ‘f’, which is of non-class type ‘TagLib::FileRef(TagLib::FileName) {aka TagLib::FileRef(const char*)}’
EN

回答 1

Stack Overflow用户

发布于 2012-06-07 14:45:31

两种版本--注释和未注释--都是错误的。在Unix上,TagLib需要const char *文件名。从QString获取的最好方法是使用QFile::encodeName()。所以你应该有这样的东西:

代码语言:javascript
复制
TagLib::FileRef f(QFile::encodeName(file).constData());
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10579419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档