title: Using std::string in QML
body: <p>I have a STL codebase that need to be shared between a QtQuick 2.0 application (the graphical interface) and a purely STL application (the server). The interface can derive its classes from the shared STL codebase, so it can have <code>Q_PROPERTY</code>s, signals, slots, etc. but the shared data structures need to remain STL-only.</p>
  
  <p>I'd like to avoid data duplication (<code>std::string</code> -> <code>QString</code>, etc.) so I tried to use <code>std::string</code> directly within the <code>Q_PROPERTY</code> system. Using <code>Q_DECLARE_METATYPE(std::string)</code> and <code>qRegisterMetaType&lt;std::string&gt;();</code> and declaring properties like:</p>
  
  <pre><code>Q_PROPERTY(QString stldata READ stldata WRITE setSTLData NOTIFY stldataChanged)
  </code></pre>
  
  <p>makes my code compile, but QML still doesn't like <code>std::string</code>s.</p>
  
  <p>Writing a text field with:</p>
  
  <pre><code>Text
  {
   text: myserviceinterface.stldata
  }
  </code></pre>
  
  <p>produces a warning saying <code>Unable to assign std::string to QString</code>, while appending an existing QML string:</p>
  
  <pre><code>Text
  {
   text: "text: " + myserviceinterface.stldata
  }
  </code></pre>
  
  <p>makes the <code>Text</code> control display a weird <code>QVariant(std::string)</code>.</p>
  
  <p>What am I doing wrong?</p>