我正在尝试编写一个简单的程序来查找 TagLib (http://developer.kde.org/~wheeler/taglib.html) 的工作原理。该程序适用于代码中的注释。但是当我更改代码时,我得到了这些我无法解决的错误。这是代码
#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;
}
在编译我得到这个错误
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*)}’