Simplified version of the code which gives the same error:

Qt Code:
  1. #include <QApplication>
  2. #include <QtCore>
  3. #include <QStandardItemModel>
  4. #include <QTableView>
  5. #include <QtGui>
  6.  
  7. using namespace std;
  8.  
  9. class MyObject {
  10.  
  11. };
  12.  
  13. Q_DECLARE_METATYPE(MyObject)
  14.  
  15.  
  16. class PaintDelegate : public QStyledItemDelegate {
  17.  
  18. public:
  19. PaintDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {}
  20.  
  21. void paint(QPainter *painter, const QStyleOptionViewItem &option,
  22. const QModelIndex &index) const
  23. {
  24. if (qVariantCanConvert<MyObject>(index.data(Qt::UserRole + 1))) {
  25. MyObject myObj = qVariantValue<MyObject>(index.data(Qt::UserRole + 1));
  26. } else {
  27. QStyledItemDelegate::paint(painter, option, index);
  28. }
  29. }
  30.  
  31. };
  32.  
  33. int main(int argc, char** argv)
  34. {
  35. QApplication app( argc, argv );
  36.  
  37. QStandardItem * item = new QStandardItem("item 1");
  38. item->setData(qVariantFromValue(MyObject()));
  39. model->setItem(0, 0, item);
  40. QTableView * tableView2 = new QTableView();
  41. tableView2->setModel(model);
  42. tableView2->setItemDelegate(new PaintDelegate);
  43. tableView2->show();
  44.  
  45. extern void updateModel(QStandardItemModel*);
  46. QtConcurrent::run(updateModel, model);
  47.  
  48. return app.exec();
  49. }
  50.  
  51. void updateModel(QStandardItemModel* model){
  52. for (;;){
  53. model->item(0, 0)->setData(qVariantFromValue(MyObject()));
  54. }
  55. }
To copy to clipboard, switch view to plain text mode