c++ - can't read tag with TagLib -


downloaded taglib 1.9 https://taglib.github.io/ , compiled instructions provided in install file.

the code below crashes error "the program has unexpectedly finished."

#include "mainwindow.h" #include <qapplication> #include <qdebug>  #include <taglib/mp4file.h>  #include <taglib/mpegfile.h> #include <taglib/fileref.h> #include <taglib/taglib.h> #include <taglib/tag.h>  int main(int argc, char *argv[]) {     qapplication a(argc, argv);      taglib::filename fn(qstring("c:/users/bill/desktop/02 wrong.mp3").tostdstring().c_str());     taglib::fileref ref(fn);      qdebug() << qstring::fromstdstring(std::string(ref.tag()->artist().tocstring()));     return a.exec(); } 

running in debug mode show me null dereference fileref.cpp @

bool fileref::isnull() const {   return !d->file || !d->file->isvalid(); } 

running windows 10 insider preview static built qt 5.0.2

i've toiled , toiled , found no helpful result.

the pointer returned qstring.tostdstring()..c_str() valid while qstring object still alive. in case that's on line you're creating it.
either keep reference qstring or don't use qstring @ all.

taglib::fileref ref("c:/users/bill/desktop/02 wrong.mp3"); qdebug() << ref.tag()->artist().tocstring(); 

furthermore should add error checks. here's example without using qt:

#include <taglib/fileref.h> #include <taglib/taglib.h> #include <taglib/tag.h>  int main(int argc, char *argv[]) {     taglib::fileref ref("./falco benz - hat tricks (original mix).mp3");     if(!ref.isnull() && ref.tag() != null) {         std::cout << ref.tag()->artist().tocstring() << std::endl;     } } 

if omit error checks, , file not exists, segfault.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -