Results 1 to 4 of 4

Thread: simplest / best way to fuse several files with QT?

  1. #1
    Join Date
    Oct 2006
    Posts
    13
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default simplest / best way to fuse several files with QT?

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: simplest / best way to fuse several files with QT?

    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.

  3. The following user says thank you to wysota for this useful post:

    Havard (18th June 2007)

  4. #3
    Join Date
    Oct 2006
    Posts
    13
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: simplest / best way to fuse several files with QT?

    using QByteArray QIODevice::readAll () ?

    Havard

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: simplest / best way to fuse several files with QT?

    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:
    Qt Code:
    1. QFile reading;
    2. QFile writing;
    3. //...
    4. QByteArray buffer;
    5. while(!reading.atEnd()){
    6. buffer = reading.read(1024*1024); //1MB
    7. writing.write(buffer);
    8. }
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to wysota for this useful post:

    Havard (18th June 2007)

Similar Threads

  1. Replies: 5
    Last Post: 22nd September 2006, 08:04
  2. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.