I'm trying to learn how to use QDataStream for serializing my data and then read it out again later. However, I'm having a trouble with reading out a QString.

The code is just "Hello World" type of app that is just used to see how things work instead of doing anything actually useful.

Qt Code:
  1. QFile outFile( "output.txt" );
  2. outFile.open( IO_WriteOnly );
  3.  
  4. QDataStream outStream( &outFile );
  5.  
  6. outStream << "The beginning of a series of numbers";
  7.  
  8. for (int i = 0; i < 50000; i++)
  9. {
  10.  
  11. outStream << (Q_INT32) i;
  12.  
  13. }/* end loop through numbers */
  14.  
  15. double outFloat = 3.1516342315;
  16.  
  17. double* addressOfFloat = &outFloat;
  18.  
  19. outStream << outFloat;
  20.  
  21. outStream << "The end of the series of numbers. Have a nice day.";
  22.  
  23. outFile.close( );
To copy to clipboard, switch view to plain text mode 

Opening up the binary file, everything looks to be in there correctly. The strings show up along with the binary for all of the numbers.

Reading out, however, is a different issue.

Qt Code:
  1. QFile inFile( "output.txt" );
  2. inFile.open( IO_ReadOnly );
  3. QDataStream inStream( &inFile );
  4.  
  5. Q_INT32 data[50000];
  6.  
  7. QString string;
  8.  
  9. inStream >> string;
  10.  
  11. for (int i = 0; i < 50000; i++)
  12. {
  13.  
  14. inStream >> data[i];
  15.  
  16. }
  17.  
  18. double doubleCheck;
  19. inStream >> doubleCheck;
  20.  
  21. inStream >> string;
  22.  
  23. inFile.close();
To copy to clipboard, switch view to plain text mode 

When I take a look at the strings that were read in, it shows up as a string of ??'s instead of the string that I output. This occurs the same whether I'm on Sun or Windows. Am I forgetting some function call?

Thanks in advance for any help.