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

QDrag on mac sometimes causes a crash when scrolling

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: P2: Important P2: Important
    • None
    • 5.0.0 Beta 1, 5.0.0 Beta 2
    • GUI: Drag and Drop
    • None
    • Mac OSX 10.7.5, Mac OSX 10.8.2
    • macOS

      Sample program is below. Unfortunately, I haven't found a reliable way to reproduce the bug but I can usually trigger it in a few seconds by spamming the up and down arrow keys while dragging and dropping the squares off the window. I believe dragging off the window is necessary so the drag will play the animation where it moves the thumbnail back to the source(I haven't observed it happening when this animation did not occur).

      Sometimes I get this error as well:

      QDragManager::drag in possibly invalid state

      #include <QtGui/QApplication>
      
      #include <QtWidgets/QGraphicsView>
      #include <QtGui/QGraphicsScene>
      #include <QtGui/QGraphicsObject>
      #include <QtGui/QDrag>
      #include <QtCore/QMimeData>
      #include <QtGui/QGraphicsSceneMouseEvent>
      #include <QtGui/QImage>
      #include <QtGui/QPixmap>
      
      class DragTestObject : public QGraphicsObject
      {
      public:
          DragTestObject(int position)
          {
              setX(10);
              setY(110 * position);
          }
      
          virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
          {
              painter->fillRect(0, 0, 100, 100, QBrush(Qt::black));
          }
      
          virtual QRectF boundingRect() const
          {
              return QRectF(0, 0, 100, 100);
          }
      
      protected:
          virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
          {
              event->accept();
      
              if(event->buttons() == Qt::LeftButton)
              {// buttons confirms that left button is the only button pressed
                  setCursor(Qt::ClosedHandCursor);
              }
          }
      
          virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
          {
              if(event->buttons() == Qt::LeftButton)
              {
                  int dist = QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length();
                  if(dist >= QApplication::startDragDistance())
                  {
                      performDrag();
                  }
              }
          }
      
      private:
          void performDrag()
          {
              QMimeData *mimeData = new QMimeData();// deleted by Qt after the drag exec
      
              QDrag *drag = new QDrag(this);//deleted by Qt after exec
              drag->setMimeData(mimeData);
      
              QImage image(40, 40, QImage::Format_RGB32);
              image.fill(Qt::blue);
      
              drag->setPixmap(QPixmap::fromImage(image));
              drag->exec();
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QGraphicsView view;
      
          QGraphicsScene scene;
      
          view.setScene(&scene);
      
          for(int i = 0; i < 10; ++i)
          {
              scene.addItem(new DragTestObject(i));
          }
      
          view.fitInView(0, 0, 150, 150, Qt::KeepAspectRatio);
      
          view.show();
      
          return a.exec();
      }
      

        1. Allocations.trace.tgz
          8.73 MB
          Teemu Katajisto
        2. trace.txt
          8 kB
          Teemu Katajisto
        3. CrashReport.log
          43 kB
          Dair Grant
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Unassigned Unassigned
            eabbottbrenner Eric Abbott-Brenner
            Votes:
            4 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes