This is what it should be:
Qt Code:
  1. // The Two Files are here.
  2. QString ticketName = ticketComboBox->currentText();
  3. QFile *ticket = new QFile(ticketName, NULL);
  4. ticket->open(QIODevice::ReadOnly);
  5. QFileInfo ti( ticketName );
  6.  
  7. QString fileName = directoryComboBox->currentText();
  8. QFile *file = new QFile(fileName, NULL);
  9. file->open(QIODevice::ReadOnly);
  10. QFileInfo fi( fileName );
  11.  
  12. // now put the two files together.
  13. QFile prnFile("out.prn");
  14. if (!outPrn.open(QIODevice::WriteOnly))
  15. return;
  16.  
  17. //first write the ticket
  18.  
  19. qint64 totalSize = ticket->size();
  20. qint64 chunkSize = 2048; //you can increase it and decrease it as you will
  21.  
  22. char *readBuffer = new char[chunkSize];
  23. while ( totalSize )
  24. {
  25. if( chunkSize > totalSize )
  26. chunkSize = totalSize;
  27. qint64 actuallyRead = ticket->read( readBuffer, chunkSize );
  28. if( actuallyRead > 0 )
  29. prnFile.write( readBuffer, actuallyRead );
  30. else
  31. break;
  32. totalSize -= actuallyRead;
  33. }
  34.  
  35. //Now Write the PDF file
  36. qint64 ptotalSize = file->size();
  37. qint64 pchunkSize = 2048; //you can increase it and decrease it as you will
  38.  
  39. char *preadBuffer = new char[pchunkSize];
  40. while ( ptotalSize )
  41. {
  42. if( pchunkSize > ptotalSize )
  43. pchunkSize = ptotalSize;
  44. qint64 pactuallyRead = file->read( preadBuffer, pchunkSize );
  45.  
  46. if( pactuallyRead > 0 )
  47. prnFile.write( preadBuffer, pactuallyRead );
  48. else
  49. break;
  50. ptotalSize -= pactuallyRead;
  51. }
  52.  
  53. // And when you're done:
  54. delete[] preadBuffer;
  55. prnFile.flush();
  56. delete ticket;
  57. delete file;
To copy to clipboard, switch view to plain text mode