I made a QListView which has a source of QStandardItemModel. I set the view to have the following settings

Qt Code:
  1. setMovement(QListView::Snap);
  2. setResizeMode(QListView::Adjust);
  3. setSpacing(5);
  4. setViewMode(QListView::IconMode);
To copy to clipboard, switch view to plain text mode 

My model's item is a QStandardItem and i added my "metatype registered value" at Qt::UserRole + 1. When I started draging the item in my view the whole things just crushes, but when i took my metatype registered value in my item it works fine. This will only happen when i drag those icons. I have accessed and displayed my custom data through the modelIndex and its fine no crushes.

below is how i declare my metatype value

Qt Code:
  1. struct s_SqlListInfo
  2. {
  3. QVariant queryName;
  4. QVariant dataBaseName;
  5. QList <QString> reqTableList;
  6. QString sqlStatement;
  7. };
  8.  
  9. // Qt MetaType Declaration
  10. Q_DECLARE_METATYPE(s_SqlListInfo)
  11.  
  12. //spot where i added my value to the item
  13.  
  14. QVariant myVal = hander->list().at(0); // hander->list() ,returns a QList of Qvariant with my custom data
  15. if (myVal .canConvert<s_SqlListInfo>())
  16. {
  17. s_SqlListInfo info = myVal .value<s_SqlListInfo>();
  18.  
  19.  
  20. item->setData(info.queryName.toString(),Qt::DisplayRole);
  21. item->setData(QIcon(":/ListIcon.png"),Qt::DecorationRole);
  22. item->setData(myVal ,Qt::UserRole+1); // spot where i added my custom data
  23. item->setData(info.sqlStatement,Qt::ToolTipRole);
  24. item->setFlags(item->flags()& ~Qt::ItemIsEditable);
  25.  
  26. m_userListModel->appendRow(item);
  27. }
To copy to clipboard, switch view to plain text mode