Program works on Linux but not on OSX
-
I have a program that is similar to a music library. It loads a folder and gets the tags from the mp3 file and list it in a MainWindow using taglib.
This is a snipet of the code that gets the tags
TagLib::FileRef f(list[PATH].toAscii()); TagLib::Tag *tag = f.tag(); list.replace(TITLE , QString::fromStdString8(tag->title().to8Bit())); list.replace(TIME , "Not Yet"); list.replace(ARTIST , QString::fromStdString(tag->artist().to8Bit())); list.replace(ALBUM , QString::fromStdString(tag->album().to8Bit())); list.replace(GENRE , QString::fromStdString(tag->genre().to8Bit())); std::ostringstream oss; oss << tag->track(); list.replace(TRACK , QString::fromStdString(oss.str().c_str()));
My friend used this on ubuntu linux and it worked, he can load a folder and get the mp3 tags. However, when I try to do it on OSX, the program runs, but when I try to load a folder, the program crashes. When I comment out these few lines, I can load the folder but, obviously I won't get the tags. My Qt uses the OSX clang compiler, not sure if that's a factor...
//list.replace(TITLE , QString::fromStdString8(tag->title().to8Bit())); list.replace(TIME , "Not Yet"); //list.replace(ARTIST , QString::fromStdString(tag->artist().to8Bit())); //list.replace(ALBUM , QString::fromStdString(tag->album().to8Bit())); //list.replace(GENRE , QString::fromStdString(tag->genre().to8Bit()));
-
When I open osx's crash report, I get this, but I'm not sure if this is actually useful... https://www.dropbox.com/s/8c3vpsg6jzjkc2j/423432.txt?dl=0
-
I doubt the problem is with TagLib.
From the description, and the way you've fixed it (temporarily), it's almost definitely that f.tag() is returning NULL. So you have not constructed your FileRef correctly, meaning that the path is not correct, or not the proper form, or FileRef somehow wasn't able to parse it.
In any case, your code should always be checking tag before using it. That will fix the crash. Then figure out why the path you passed in to the constructor didn't work.
-
@Dyami-Caliri I have finally got my ubuntu virtualbox working, and the program is working fine on there. So I think I will just stick to ubuntu for now. Although I still don't understand why it works on Linux but not on OsX when I'm using the same exact code.
-
@devbrs The most likely cause is that the path you use on the Mac has non-ASCII characters in it. If that's the case, you would need to use UTF8 instead of ASCII. I don't know what type list is, so I don't know what method you need, but I'm guessing toUTF8().
There could be other things wrong with the code, that happen to work on Linux but don't work on OSX. For example, PATH as an index seems fairly odd. But you haven't given us the rest of the relevant code.
If the path doesn't have non-ASCII characters in it, maybe you should post more of your code.
-
Here is the code + some other files included in the project
qtunesThe main code is in MainWindow.cpp, my professor gave us the code, it's basically a Music Library/Player, kind of like iTunes, but we had to implement TagLib to read the mp3 tags. The code isn't very clean sorry.
-
@devbrs You certainly must check if taglib is null. And you must use toUTF8() instead of toAscii().
The last problem is that some of the string conversion functions in TagLib don't appear to work with the QString conversion functions.
Namely the functions that create c++ string and wstring objects:
QString::fromStdString(tag->title().to8Bit()); QString::fromStdWString(tag->title().toWString());
The functions that return c style string pointers do work:
QString::fromWCharArray(tag->title().toCWString()); QString(tag->title().toCString(true));
Now, why the string functions work on Linux and not on the Mac, I don't know. Perhaps you could delve into it.