Results 1 to 3 of 3

Thread: Why isn't this joining files correctly?

  1. #1
    Join Date
    Nov 2012
    Posts
    20
    Thanked 1 Time in 1 Post

    Default Re: Why isn't this joining files correctly?

    I'm trying to join two or more files together.

    For each new file to add I call this function:

    Qt Code:
    1. void MainWindow::mergemp3(QString fname) //fname is the new file to add
    2. {
    3.  
    4.  
    5. QFile mp3name (fname);
    6. mp3name.open(QIODevice::ReadOnly);
    7.  
    8.  
    9. QByteArray temp= mp3name.readAll();
    10. mergedaudio +=temp; //mergedaudio is a global qbytearray which is the resulting joined up file
    11.  
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    Then I write out the merged file:

    Qt Code:
    1. QFile test("testout.mp3");
    2. test.open(QIODevice::WriteOnly);
    3. QDataStream writetest(&test);
    4. writetest<< mergedaudio;
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by tom989; 6th January 2013 at 23:35.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Why isn't this joining files correctly?

    QDataStream is the wrong tool for this job and completely unnecessary: just use QIODevice::write();

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why isn't this joining files correctly?

    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?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Joining together a QComboBox, QStringList, and enum
    By Phlucious in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2012, 17:47
  2. How to use QProgressBar correctly
    By jshafferman in forum Qt Programming
    Replies: 6
    Last Post: 21st April 2011, 15:01
  3. Replies: 1
    Last Post: 20th October 2010, 07:19
  4. Joining tables into QTableView
    By SykeS in forum Qt Programming
    Replies: 10
    Last Post: 8th June 2010, 11:39
  5. making the printer correctly interpret pcl files
    By momesana in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2008, 17:41

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.