QVariant : save : unable to save type 128
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 :
Quote:
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
Code:
qRegisterMetaTypeStreamOperators<void*>("void*");
but to no avail, same message appears .. So I'm stuck and I can't figure out what is wrong. Anybody has a hint ?
Code:
QMap<int, QVariant>
{
QMap<int, QVariant> roles;
roles.insert(Qt::DisplayRole, data(index,Qt::DisplayRole));
roles.insert(ITEM_TYPE_ROLE, data(index,ITEM_TYPE_ROLE));
// store a void* here
roles.insert(ITEM_POINTER_ROLE, qVariantFromValue((void *) index.internalPointer())) ;
return roles;
}
Code:
MyModel::mimeData(const QModelIndexList & indexes) const
{
if (indexes.count() <= 0)
return 0;
if (types.isEmpty())
return 0;
QModelIndexList::ConstIterator it = indexes.begin();
for (; it != indexes.end(); ++it)
{
QMap<int,QVariant> mapz = itemData(*it);
stream << mapz; // QVariant : save : unable to save type 128
}
data->setData(format, encoded);
return data;
}