title: Dragging from a QAbstractItemModel drops empty string
body: <p>I derived a custem model from <code>QAbstractItemModel</code> and implemented drag&amp;drop support by</p>
  
  <ol>
  <li>overloading a <code>flags()</code> method that returns <code>Qt::ItemIsDragEnabled</code> where applicable,</li>
  <li>overloading <code>supportedDropActions</code> and</li>
  <li>implementing <code>mimeData()</code> to properly return a <code>QMimeData</code> object with some string set for the <code>text/plain</code> format.</li>
  </ol>
  
  <p>When I setup this model in a <code>QTreeView</code> and enable dragging via <code>setDragEnabled(true)</code>, I can pick items from the tree view and drag them. For example, I can drag an item and drop it onto a <code>QLineEdit</code>, which in turn will display the string that the model returned via <code>mimeData()</code>.</p>
  
  <p>However, when I drag an item and drop it onto another application's widgets (such as notepad or simply a second instance of my application) an empty string gets dropped.</p>
  
  <p>I found another clue using the <em>Drop site example</em> shipped with Qt: When I drag an item over it, it correctly shows that there is <code>text/plain</code> available and it even displays the string associated with it. Yet, when I drop the item I get an empty string again in the <code>dropEvent()</code>...</p>
  
  <h2>Sourcecode</h2>
  
  <p>ssce.pro:</p>
  
  <pre><code>QT += core gui widgets
  TARGET = ssce
  TEMPLATE = app
  SOURCES += main.cpp
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;QtCore&gt;
  #include &lt;QtWidgets&gt;
  
  struct Model: public QAbstractItemModel {
      int rowCount(const QModelIndex &amp;parent) const {
          return parent.isValid() ? 0 : 1;
      }
  
      int columnCount(const QModelIndex &amp;parent) const {
          return 1;
      }
  
      QModelIndex index(int row, int column, const QModelIndex &amp;parent) const {
          return parent.isValid() ? QModelIndex() : createIndex(row, column, static_cast&lt;void *&gt;(0));
      }
  
      QModelIndex parent(const QModelIndex &amp;child) const {
          return QModelIndex();
      }
  
      Qt::ItemFlags flags(const QModelIndex &amp;index) const {
          return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
      }
  
      QVariant data(const QModelIndex &amp;index, int role) const {
          return (role == Qt::DisplayRole) ? "Test item" : QVariant();
      }
  
      QStringList mimeTypes() const {
          return QStringList("text/plain");
      }
  
      QMimeData *mimeData(const QModelIndexList &amp;indexes) const {
          QMimeData *d = new QMimeData();
          d-&gt;setText("hello world");
          return d;
      }
  
      Qt::DropActions supportedDropActions() const {
          return Qt::CopyAction;
      }
  };
  
  
  int main(int argc, char *argv[]) {
      QApplication a(argc, argv);
  
      QDialog d;
      QVBoxLayout l;
  
      QLineEdit e;
      l.addWidget(&amp;e);
  
      QTreeView v;
      Model m;
      v.setModel(&amp;m);
      v.setDragEnabled(true);
      l.addWidget(&amp;v);
  
      d.setLayout(&amp;l);
      d.show();
      return a.exec();
  }
  </code></pre>
  
  <p>Description:
  Run this and you can drag the item from the tree view into the line edit, it will display <em>hello world</em> then. Drop the item anywhere else, including the line edit of a second instance of the sample application, and nothing will happen.</p>