PDA

View Full Version : Why isn't this joining files correctly?



tom989
6th January 2013, 23:35
I'm trying to join two or more files together.

For each new file to add I call this function:



void MainWindow::mergemp3(QString fname) //fname is the new file to add
{


QFile mp3name (fname);
mp3name.open(QIODevice::ReadOnly);


QByteArray temp= mp3name.readAll();
mergedaudio +=temp; //mergedaudio is a global qbytearray which is the resulting joined up file


}


Then I write out the merged file:



QFile test("testout.mp3");
test.open(QIODevice::WriteOnly);
QDataStream writetest(&test);
writetest<< mergedaudio;


The resulting file (mp3) doesn't play correctly. I know this can be done as I used standard c++ to do it.

Any idea what I've done wrong?

Added after 5 minutes:

Oops. Was using the << which is for formatted data.

ChrisW67
7th January 2013, 03:58
QDataStream is the wrong tool for this job and completely unnecessary: just use QIODevice::write();

amleto
7th January 2013, 14:23
surely you end up with two ID3 tags in the merged file - one somewhere in the middle of the file! Isn't this a problem?