SRD

setdata

SRD
Mar 9th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. // I have a class as follows (the MyTreeItem class does not inherit QObject).
  2.  
  3. class MyTreeItem
  4. {
  5.     // ...
  6. };
  7.  
  8. Q_DECLARE_METATYPE(MyTreeItem)
  9.  
  10. // I'm trying to add an item to my treeview, but not sure how to construct this class with
  11. // QVariant which is what QVariant::setData takes ...
  12.  
  13.     bool QAbstractItemModel::setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
  14.  
  15. // And here is how I'm trying to add an item to my tree ...
  16.  
  17.     QList<QVariant> name;
  18.     name << new_name << "";
  19.  
  20.     const QModelIndex parent = treeModel->index(0, 0);
  21.  
  22.     MyTreeItem *newItem = new MyTreeItem(name);
  23.  
  24.     treeModel->insertRow(0, parent);
  25.    
  26.     treeModel->setData(treeModel->index(0, 0, parent), QVariant(newItem));
  27.    
  28. /* The error I get in setData above is ...
  29.              
  30. error: use of deleted function ‘QVariant::QVariant(void*)’ treeModel->setData(treModel->index(0, 0, parent), QVariant(newItem));
  31.                 ^
  32.  
  33. */
Advertisement
Add Comment
Please, Sign In to add comment