本文介绍了Qt4:从QAbstractTableModel读取默认的mimeData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下, QAbstractTableModel 类具有 mimeData()函数,该函数返回 QMimeData 对象,该对象的数据集已设置为已编码 QModelIndexList (请参见此处).我想在一个重载的 dropMimeData()函数中解压缩这些数据,但是无法弄清楚如何将这个 QMimeData 转换回一个QcodeIndexList.code>我尝试了明显的方法:

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;
}

但收到错误消息:

 no match for ‘operator>>’ in ‘stream >> ((myTableModel*)this)->QAbstractTableModel::index’

因为没有>>运算符用于QModelIndex.

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.

推荐答案

多谢了,多亏了Kaleb Peterson在旧问题的链接上:

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;
}

这篇关于Qt4:从QAbstractTableModel读取默认的mimeData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 19:39