title: How can I convert QByteArray to string in Qt 5.3?
body: <p>I am using some functions to convert <code>QVector's</code> to <code>QByteArray's</code>, for example:</p>
  
  <pre><code>QByteArray Serialize::serialize(QVector&lt;double&gt; data)
  {
      QByteArray byteArray;
      QDataStream out(&amp;byteArray, QIODevice::WriteOnly);
      out &lt;&lt; data;
      return byteArray;
  }
  
  void Serialize::deserialize(QByteArray byteArray, QVector&lt;double&gt; *data)
  {
      QDataStream in(&amp;byteArray, QIODevice::ReadOnly);
      in &gt;&gt; *data;
  }
  </code></pre>
  
  <p>Now, that I have the <code>QByteArray</code> I need to put it in a text file, how can I convert it to <code>QString</code>?</p>
  
  <p>I already tried the simplest way:</p>
  
  <pre><code>QString myString(data); // data - QByteArray
  </code></pre>
  
  <p>But <code>myString</code> is always empty.</p>
  
  <p>I also found the <code>toStdString()</code> function in the documentation, but it was introduced only in <strong>Qt 5.4</strong>.</p>
  
  <p>I'm using <strong>Qt 5.3</strong>.</p>
  
  <p>Follows a complete example:</p>
  
  <pre><code>#include &lt;QCoreApplication&gt;
  
  #include &lt;QDebug&gt;
  #include &lt;QVector&gt;
  #include &lt;QByteArray&gt;
  #include &lt;QDataStream&gt;
  
  QByteArray serialize(QVector&lt;double&gt; data)
  {
      QByteArray byteArray;
      QDataStream out(&amp;byteArray, QIODevice::WriteOnly);
      out &lt;&lt; data;
      return byteArray;
  }
  
  void deserialize(QByteArray byteArray, QVector&lt;double&gt; *data)
  {
      QDataStream in(&amp;byteArray, QIODevice::ReadOnly);
      in &gt;&gt; *data;
  }
  
  int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
  
      QVector&lt;double&gt; data;
      data &lt;&lt; 1.1 &lt;&lt; 2.2 &lt;&lt; 3.3 &lt;&lt; 4.4 &lt;&lt; 5.5 &lt;&lt; 6.6 &lt;&lt; 7.7 &lt;&lt; 8.8 &lt;&lt; 9.9;
  
      QByteArray byteArray = serialize(data);
      QVector&lt;double&gt; dataConverted;
      deserialize(byteArray, &amp;dataConverted);
  
      qDebug() &lt;&lt; "Data:";
      qDebug() &lt;&lt; data;
      qDebug() &lt;&lt; "ByteArray:";
      QString test(byteArray);
      qDebug() &lt;&lt; test;
      qDebug() &lt;&lt; "Data Converted:";
      qDebug() &lt;&lt; dataConverted;
  
      return a.exec();
  }
  </code></pre>
  
  <p><strong>Note</strong>: The general objective of this is to generate a <strong>SQL</strong> file with all content from the <strong>SQLite</strong> database. My double vector is converted to <code>QByteArray</code> and stored as <strong>BLOB</strong> into the database (using the serialize function). When I need to load it from the database I use the deserialize function to convert to a double vector again. Now I need to generate the <strong>SQL</strong> file with the data in the <strong>BLOB</strong> format, then I can directly import it into another database.</p>