PDA

View Full Version : [Qt6] StartDrag making crash on Qt6



Alundra
11th December 2020, 21:22
Hi!
I use a custom startDrag to avoid the pixmap which is annoying during the drag.
All worked good until Qt6, if I remove my custom startDrag everything works good but with the pixmap that I would avoid.
Here how I do the custom startDrag:

void startDrag(Qt::DropActions supportedActions) override
{
QDrag* drag = new QDrag(this);
drag->setMimeData(mimeData(selectedItems()));
drag->exec(supportedActions);
}
What would be the thing that Qt6 doesn't like with this particular piece of code where the non-override works perfectly fine?
Would be nice to have an option to disable pixmap on drag and drop for QTreeWidget/QListWidget one day surely for this kind of case when you don't want a pixmap.
Thanks a lot!

ChristianEhrlicher
12th December 2020, 10:46
Where exactly does it crash? Can you post the backtrace?

Alundra
12th December 2020, 16:46
Good idea, I downloaded the debug symbols and I saw where it crashes:


> Qt6Widgetsd.dll!QModelIndex::isValid() Line 178
Qt6Widgetsd.dll!QIconModeViewBase::indexToListView Item(const QModelIndex & index) Line 3057
Qt6Widgetsd.dll!QIconModeViewBase::itemsRect(const QList<QModelIndex> & indexes) Line 3253
Qt6Widgetsd.dll!QIconModeViewBase::filterDragMoveE vent(QDragMoveEvent * e) Line 297
Qt6Widgetsd.dll!QListView::dragMoveEvent(QDragMove Event * e) Line 893

The reason is:

+ this 0x0000000000000000 <NULL> QModelIndex *
Looks like calling the base class is making it crashes in the override:

void dragMoveEvent(QDragMoveEvent* e) override
So I removed all the call to the base class and now it's not crashing but I have less visual like the "forbidden icon" is not visible when the action is invalid during the drag operation.
Looks like without a pixmap you don't have the "forbidden icon" so it gives less feedback to the user. I wonder why it would not be possible to have just the feedback icon without pixmap.
It's still crashing when the drag is outside the widget.
Adding this addition code fixed the crash when the drag is outside the widget which is a QListWidget:

void dragLeaveEvent(QDragLeaveEvent* e) override
{
e->accept();
}
All that is strange...

ChristianEhrlicher
12th December 2020, 18:03
Can you please provide a minimal, compilable example so we can reproduce the issue?

/edit: and are you really sure it worked with 5.15?

Alundra
12th December 2020, 19:43
This code reproduces the issue, you can start to drag and drop "Item1" and you will see a crash immediately once you move the mouse during drag and drop.


#include <QApplication>
#include <QDrag>
#include <QListWidget>
#include <QMainWindow>

class CustomListWidget : public QListWidget
{
public:
CustomListWidget(QWidget* parent) : QListWidget(parent)
{}

protected:
void startDrag(Qt::DropActions supportedActions) override
{
QDrag* drag = new QDrag(this);
drag->setMimeData(mimeData(selectedItems()));
drag->exec(supportedActions);
}
};

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
CustomListWidget customListWidget(&w);
customListWidget.setMovement(QListView::Snap);
customListWidget.setViewMode(QListView::IconMode);
customListWidget.setResizeMode(QListView::Adjust);
customListWidget.setSelectionMode(QAbstractItemVie w::ExtendedSelection);
customListWidget.setDragDropMode(QAbstractItemView ::DragDrop);
customListWidget.setDefaultDropAction(Qt::MoveActi on);
customListWidget.setIconSize(QSize(64, 64));
customListWidget.setUniformItemSizes(true);
customListWidget.setSortingEnabled(true);
customListWidget.setWrapping(true);
customListWidget.addItem("Item1");
customListWidget.addItem("Item2");
w.show();
return a.exec();
}

ChristianEhrlicher
12th December 2020, 20:26
Thx for the reproducer and as I expected it's just by accident that it does not crash with Qt5. QIconModeViewBase::itemsRect() is called with an empty container due to your custom startDrag() function. The original startDrag() fills this container before calling drag->exec(). Will create a bug report for it.

/edit: Here the ink to the bugreport: https://bugreports.qt.io/browse/QTBUG-89434

Alundra
12th December 2020, 22:18
Thanks! I added myself as watcher :)