Memory leak in Qt5? How to get QMimeData deleted?

前端 未结 2 766
难免孤独
难免孤独 2021-01-18 15:52

I just provided an answer for this question and wanted to provide a working example when I noticed that newly created QMimeData instance returned by QList

2条回答
  •  难免孤独
    2021-01-18 16:08

    There is a memory leak only if you forget to delete the pointer returned by mimeData(). You have to manage the ownership as with any pointer.

    For instance, if you pass the mimeData() returned pointer to a QDrag object using setMimeData(), he will take ownership of it, and will take care of deleting it at the end of the drag operation. There is no memory leak in this case.

    See : http://doc.qt.io/qt-5/qdrag.html#setMimeData

提交回复
热议问题