简体   繁体   中英

Finding the end of a Drag and Drop operation in QAbstractItemView

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM