title: QString to unicode std::string
body: <p>I know there is plenty of information about converting <code>QString</code> to <code>char*</code>, but I still need some clarification in this question.</p>
  
  <p>Qt provides <code>QTextCodec</code>s to convert <code>QString</code> (which internally stores characters in unicode) to <code>QByteArray</code>, allowing me to retrieve <code>char*</code> which represents the string in some non-unicode encoding. But what should I do when I want to get a unicode <code>QByteArray</code>?</p>
  
  <pre><code>QTextCodec* codec = QTextCodec::codecForName("UTF-8");
  QString qstr = codec-&gt;toUnicode("Юникод");
  std::string stdstr(reinterpret_cast&lt;const char*&gt;(qstr.constData()), qstr.size() * 2 );  // * 2 since unicode character is twice longer than char
  qDebug() &lt;&lt; QString(reinterpret_cast&lt;const QChar*&gt;(stdstr.c_str()), stdstr.size() / 2); // same
  </code></pre>
  
  <p>The above code prints "Юникод" as I've expected. But I'd like to know if that is the right way to get to the unicode <code>char*</code> of the <code>QString</code>. In particular, <code>reinterpret_cast</code>s and size arithmetics in this technique looks pretty ugly.</p>