Hi

I have a custom QAbstractItemModel with drag and drop support. I reimplemented methods like mimeData() and itemData() to serialize informations I want to drag from a view to another.
It works fine with Qt 4.7.2.

Recently I had to downgrade Qt to Qt 4.6.2 (to have standard Qt libs on linux x86_64).

Now when I drag an item from a view, a Qt debug message appears, and DnD does not work :

QVariant : save : unable to save type 128
128 stands for built-in type QMetaType::VoidStar (which is exactly what I store in itemData), as if Qt was not able to serialize a QVariant(void*) into a QDataStream, which is weird because VoidStar appears to be a built-in type !

I tried redefining stream operators for void* and register them with

Qt Code:
  1. qRegisterMetaTypeStreamOperators<void*>("void*");
To copy to clipboard, switch view to plain text mode 

but to no avail, same message appears .. So I'm stuck and I can't figure out what is wrong. Anybody has a hint ?


Qt Code:
  1. QMap<int, QVariant>
  2. MyModel::itemData(const QModelIndex &index) const
  3. {
  4. QMap<int, QVariant> roles;
  5. roles.insert(Qt::DisplayRole, data(index,Qt::DisplayRole));
  6. roles.insert(ITEM_TYPE_ROLE, data(index,ITEM_TYPE_ROLE));
  7. // store a void* here
  8. roles.insert(ITEM_POINTER_ROLE, qVariantFromValue((void *) index.internalPointer())) ;
  9.  
  10. return roles;
  11. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. MyModel::mimeData(const QModelIndexList & indexes) const
  2. {
  3. if (indexes.count() <= 0)
  4. return 0;
  5. QStringList types = mimeTypes();
  6. if (types.isEmpty())
  7. return 0;
  8. QMimeData *data = new QMimeData();
  9. QString format = types.at(0);
  10. QByteArray encoded;
  11. QDataStream stream(&encoded, QIODevice::WriteOnly);
  12. QModelIndexList::ConstIterator it = indexes.begin();
  13. for (; it != indexes.end(); ++it)
  14. {
  15. QMap<int,QVariant> mapz = itemData(*it);
  16. stream << mapz; // QVariant : save : unable to save type 128
  17. }
  18. data->setData(format, encoded);
  19. return data;
  20. }
To copy to clipboard, switch view to plain text mode