Jadelabe
Jadelabe

Reputation: 37

".mp3" metadata from TagLib to QString, Qt, C++

I'm trying to rename .mp3 files using TagLib with the format "artist - album - song(year).mp3" and move them to a new directory, so far i'm using

    TagLib::FileRef f(dirIt.filePath().toStdString().c_str());

    QString newName = f.tag()->artist().toCString() + " - " + f.tag()->album().toCString() + " - " + (QString) f.tag()->track() + " (" + (QString) f.tag()->year() + ")";
    QString newPath = NewDir.absolutePath() + QDir().separator() + newName + ".mp3";
    QFile::copy(oldDir, newPath);
    QFile::remove(dirIt.filePath().toStdString().c_str());

Where "dirIt" is a QDirIterator (I'm iterating a folder where the songs are) and "oldDir" a Qstring with the absolute path of the folder i'm iterating.

My problem comes when im trying to give "newName" the desired value, i'm getting

error: invalid operands of types 'const char*' and 'const char [4]' to binary 'operator+' QString newName = f.tag()->artist().toCString() + " - " + f.tag()->album().toCString() + " - " + (QString) f.tag()->track() + " (" + (QString) f.tag()->year() + ")";

How can i solve this?

Upvotes: 0

Views: 872

Answers (1)

ixSci
ixSci

Reputation: 13718

Use format string to build the string for new name:

QString newName("%1% - %2% - %3% (%4%)");
newName = newName.arg(f.tag()->artist().toCString()).arg(f.tag()->album().toCString()).arg(f.tag()->track()).arg(f.tag()->year());

Upvotes: 1

Related Questions