By default, the QAbstractTableModel
class has a mimeData()
function that returns a QMimeData
object which has it's data set as an encoded QModelIndexList
(see here). I would like to unpack this data in an overloaded dropMimeData()
function, but can't figure out how to convert this QMimeData
back into a QModelIndexList.
I tried the obvious:
bool myTableModel::dropMimeData(const QMimeData * mimeData, Qt::DropAction action, int row, int column, const QModelIndex & parent)
{
QStringList formats = mimeData->formats();
QByteArray encodedData = mimeData->data(formats[0]);
QDataStream stream(&encodedData, QIODevice::ReadOnly);
QModelIndexList list;
stream >> index;
}
but get the error:
no match for ‘operator>>’ in ‘stream >> ((myTableModel*)this)->QAbstractTableModel::index’
because there is no >> operator for QModelIndex.
Note: this question is a much more focused version of this one. Sorry if this breaks SO ettiquete, I'm a bit new here.
6 years late, but in case someone hit the issue in the future, here's a more complete solution. It also handle the corner case where there is typed, but invalid QVariants (because they are not serializable). In my (related, but not identical) use case, I mostly cared about the source and destination QVariants to be type compatible, I didn't cared as much about the value, but the code should work.
Got it, thanks to Kaleb Peterson at the old question's link: