PDA

View Full Version : simplest / best way to fuse several files with QT?



Havard
18th June 2007, 01:07
Hi.

I want to create a composite file containing, say, a soundfile and a picturefile, but the main idea is to pile several files of unknown content into one large file... :)

Quite a simple excersise, but I am not quite sure how to use QT (properly) to accomplish this task. QDataStream seems to be the right choice, maybe added with readBytes() / writeBytes().

Anyone care to show me a samle code of how this should be done most elegantly?

thanks!

Havard

wysota
18th June 2007, 01:23
QDataStream is not the right choice. Use QFile - open one file for writing, one for reading, read all contents and write to the other file, open the second file for reading, etc.

Havard
18th June 2007, 01:43
using QByteArray QIODevice::readAll () ?

Havard

wysota
18th June 2007, 11:06
It depends. If you're not afraid files might be very big and put much strain on your computer, then you can use readAll(). Otherwise read a single chunk at a time, for example:

QFile reading;
QFile writing;
//...
QByteArray buffer;
while(!reading.atEnd()){
buffer = reading.read(1024*1024); //1MB
writing.write(buffer);
}