Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-54667

When drag&drop operation gets interrupted QDrag object doesn't get deleted in QListWidget

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3: Somewhat important P3: Somewhat important
    • 5.8
    • 5.6
    • None
    • Fedora 23, Qt5.6, gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)
    • 28dffdecdad4f3458b9aacec1a04803c7b5483a1

      When trying to track the lifetime of a drag&drop operation I noticed that the QDrag destructor will only be called if the drop is accepted by the target. If not the QDrag object stays in memory until the Qt application terminates.

      A more complete elaboration can be found here: http://stackoverflow.com/questions/37846843

      This is the code I can reproduce the behavior with:

      #include <QtWidgets>
      #include <iostream>
      
      struct TrackedMimeData : public QMimeData {
         TrackedMimeData(const QString & text) {
            std::cout << this << std::endl;
            setText(text);
         }
         ~TrackedMimeData() {
             std::cout << "~" << this << std::endl;
         }
      };
      
      struct MyListWidget : QListWidget {
         MyListWidget() {
            setDragEnabled(true);
            addItem("item1");
            addItem("item2");
         }
         QMimeData * mimeData(const QList<QListWidgetItem *>) const override {
            return new TrackedMimeData("hello");
         }
      };
      
      int main(int argsc, char *argsv[]) {
         QApplication application(argsc, argsv);
         MyListWidget gui;
         gui.show();
         return application.exec();
      }
      

      Output:

      0xa58750
      0xa4e0f0
      ~0xa4e0f0
      0xa3c6c0
      ~0xa3c6c0
      0xa51880
      0xa5ecd0
      0xa31f50
      0xa57db0
      0xa5afc0
      ~0xa5afc0
      0xa5aa70
      ~0xa5aa70
      ------ CLOSE WINDOW
      ~0xa58750
      ~0xa51880
      ~0xa5ecd0
      ~0xa31f50
      ~0xa57db0
      

      Expected output:

      0xa58750
      ~0xa58750
      0xa4e0f0
      ~0xa4e0f0
      0xa3c6c0
      ~0xa3c6c0
      0xa51880
      ~0xa51880
      0xa5ecd0
      ~0xa5ecd0
      0xa31f50
      ~0xa31f50
      0xa57db0
      ~0xa57db0
      0xa5afc0
      ~0xa5afc0
      0xa5aa70
      ~0xa5aa70
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            chehrlic Christian Ehrlicher
            major_bug major_bug
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes