title: Is it possible to mix QTextStream and QDataStream?
body: <p>Needing to read a mixed text/binary file I thought using both <code>QTextStream</code> and <code>QDataStream</code> together would be the most effective.</p>
  
  <p>The file looks like this:</p>
  
  <blockquote>
    <p>Some line of text<BR> Another line of text<BR> 42<BR> &lt;100 bytes of
    binary data><BR> 12<BR> &lt;100 bytes of binary data><BR> ... etc. (an
    int in a line, then 100 bytes of binary data in a line, and so on)</p>
  </blockquote>
  
  <p>Here is the initialization, variables etc.:</p>
  
  <pre><code>// a QFile named in is already opened successfully as binary (without QIODevice::Text)
  QTextStream stream(&amp;in);
  QDataStream data(&amp;in);
  int nr;
  int nr_bytes;
  char buffer[200];
  </code></pre>
  
  <p>First I tested whether reading from one stream advances the other. If I read 10 bytes with <code>data.readRawData()</code> from the file, then <code>stream.readLine()</code> will read "of text", so it works!</p>
  
  <p>However, if I do the following, from the beginning of the example file:</p>
  
  <pre><code>stream.readLine();
  stream.readLine();
  for (/*...*/)
  {
      stream &gt;&gt; nr;
      stream.readLine();
      nr_bytes = data.readRawData(buffer, 100);
      stream.readLine();
  }
  </code></pre>
  
  <p>it does not work, and the buffer remains empty. Strangely, the numbers (42, 12, etc.) are read correctly into <code>nr</code>, no matter how many bytes I read with <code>data.readRawData()</code>. It can be 1000 bytes, it still does not seem to read anything. The value in <code>nr_bytes</code>, however, indicates that the bytes are successfully read! Still strange, that the last readLine in the loop actually reads the binary data (at least until it encounters a zero, a line feed or other special characters). This means, that <code>data.readRawData()</code> did not read anything at all, but it still has the number of required bytes in its return value.</p>
  
  <p>Does this mean I cannot use <code>QTextStream</code> and <code>QDataStream</code> together, or am I doing something else wrong?</p>