在QAbstractItemView中找到拖放操作的结束 [英] Finding the end of a Drag and Drop operation in QAbstractItemView

查看:151
本文介绍了在QAbstractItemView中找到拖放操作的结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了由QSortFilterProxyModel继承的自定义代理模型。我的上述代理模型的源模型也是QAbstractTableModel继承的自定义模型。然后我将自定义代理模型设置为QTableView。

I created custom proxy model inherited by QSortFilterProxyModel. My source model for the above mentioned proxy model is also a custom model inherited by QAbstractTableModel. Then I set my custom proxy model to a QTableView.

在这个自定义代理模型中,我重新实现了mimeData(..)函数。如下。

In this custom proxy model, I reimplemented the mimeData(..) function. It is as follows.

QMimeData* CustomProxyModel::mimeData( const QModelIndexList & rListIndexes ) const
{
    QMimeData *pMimeData = new QMimeData();

    //some code here

    connect(pMimeData, SIGNAL( destroyed(QObject*) ), this, SLOT( OnDestroyDraggedItem() ) );

    return pMimeData;
}

在Qt4.7中,用户将一个QTableView在某处,OnDestroyDraggedItem()槽被调用。换句话说,QMimeData对象在拖放操作后立即被删除。

In Qt4.7, soon after the user dropped an item of the QTableView into somewhere, OnDestroyDraggedItem() slot was called. In other words, QMimeData object is deleted soon after the drag and drop operation.

但是在Qt 5.1中,OnDestroyDraggedItem()槽从不被调用。换句话说,QMimeData对象在拖放操作后永远不会被删除。

But in Qt 5.1, OnDestroyDraggedItem() slot is never called. In other words, QMimeData object is never deleted after a drag and drop operation.

我做错了什么?
或者有拖拽操作后Qt 5.1内存泄漏吗?
有没有另一种方法来找到拖放操作的结束?

Am I doing something wrong? Or Has Qt 5.1 a memory leak after a drag and drop operation ? Is there another way to find a end of a drag and drop operation ?

推荐答案

但是你不能只是继承 QMimeData 并在析构函数中做一些事情?
应该是小而安全的代码当然 - 抛出异常在析构函数可以导致奇怪的行为:)

Maybe it's a bit late - but can't you just inherit QMimeData and do something in the destructor? Should be small and safe code of course - throwing exceptions in destructors can cause strange behavior :)

这篇关于在QAbstractItemView中找到拖放操作的结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆