tags:

views:

100

answers:

1

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.

A: 

Got it, thanks to Kaleb Peterson at the old question's link:

bool ObjectAnimation::dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent)
{
  QStringList formats = data->formats();
  QByteArray encodedData = data->data(formats[0]);
  QDataStream stream(&encodedData, QIODevice::ReadOnly);

  int row, column;
  stream >> row >> column;

  qDebug() << "row: " << row << " column:" << column;

  return false;
}
Boatzart