Finding the end of a Drag and Drop operation in QAbstractItemView

对着背影说爱祢 提交于 2020-01-05 10:33:42

问题


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.

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

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.

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

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 ?


回答1:


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 :)



来源:https://stackoverflow.com/questions/23709529/finding-the-end-of-a-drag-and-drop-operation-in-qabstractitemview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!