PDA

View Full Version : QVariant : save : unable to save type 128



capbee
15th July 2013, 09:10
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


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 ?



QMap<int, QVariant>
MyModel::itemData(const QModelIndex &index) const
{
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;
}


QMimeData*
MyModel::mimeData(const QModelIndexList & indexes) const
{
if (indexes.count() <= 0)
return 0;
QStringList types = mimeTypes();
if (types.isEmpty())
return 0;
QMimeData *data = new QMimeData();
QString format = types.at(0);
QByteArray encoded;
QDataStream stream(&encoded, QIODevice::WriteOnly);
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;
}