Results 1 to 7 of 7

Thread: [Qt6] StartDrag making crash on Qt6

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation [Qt6] StartDrag making crash on Qt6

    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:
    Qt Code:
    1. void startDrag(Qt::DropActions supportedActions) override
    2. {
    3. QDrag* drag = new QDrag(this);
    4. drag->setMimeData(mimeData(selectedItems()));
    5. drag->exec(supportedActions);
    6. }
    To copy to clipboard, switch view to plain text mode 
    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!
    Last edited by Alundra; 11th December 2020 at 22:32.

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt6] StartDrag making crash on Qt6

    Where exactly does it crash? Can you post the backtrace?

  3. #3
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [Qt6] StartDrag making crash on Qt6

    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:
    Qt Code:
    1. void dragMoveEvent(QDragMoveEvent* e) override
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. void dragLeaveEvent(QDragLeaveEvent* e) override
    2. {
    3. e->accept();
    4. }
    To copy to clipboard, switch view to plain text mode 
    All that is strange...
    Last edited by Alundra; 12th December 2020 at 18:21.

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt6] StartDrag making crash on Qt6

    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?
    Last edited by ChristianEhrlicher; 12th December 2020 at 19:09.

  5. #5
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [Qt6] StartDrag making crash on Qt6

    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.
    Qt Code:
    1. #include <QApplication>
    2. #include <QDrag>
    3. #include <QListWidget>
    4. #include <QMainWindow>
    5.  
    6. class CustomListWidget : public QListWidget
    7. {
    8. public:
    9. CustomListWidget(QWidget* parent) : QListWidget(parent)
    10. {}
    11.  
    12. protected:
    13. void startDrag(Qt::DropActions supportedActions) override
    14. {
    15. QDrag* drag = new QDrag(this);
    16. drag->setMimeData(mimeData(selectedItems()));
    17. drag->exec(supportedActions);
    18. }
    19. };
    20.  
    21. int main(int argc, char *argv[])
    22. {
    23. QApplication a(argc, argv);
    24. CustomListWidget customListWidget(&w);
    25. customListWidget.setMovement(QListView::Snap);
    26. customListWidget.setViewMode(QListView::IconMode);
    27. customListWidget.setResizeMode(QListView::Adjust);
    28. customListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
    29. customListWidget.setDragDropMode(QAbstractItemView::DragDrop);
    30. customListWidget.setDefaultDropAction(Qt::MoveAction);
    31. customListWidget.setIconSize(QSize(64, 64));
    32. customListWidget.setUniformItemSizes(true);
    33. customListWidget.setSortingEnabled(true);
    34. customListWidget.setWrapping(true);
    35. customListWidget.addItem("Item1");
    36. customListWidget.addItem("Item2");
    37. w.show();
    38. return a.exec();
    39. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt6] StartDrag making crash on Qt6

    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
    Last edited by ChristianEhrlicher; 12th December 2020 at 21:42.

  7. #7
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [Qt6] StartDrag making crash on Qt6

    Thanks! I added myself as watcher

Similar Threads

  1. On the way of making an app installable
    By franky in forum Newbie
    Replies: 6
    Last Post: 5th February 2017, 11:14
  2. Replies: 0
    Last Post: 3rd November 2015, 18:58
  3. Crash gracefully? No crash!
    By lni in forum Qt Programming
    Replies: 0
    Last Post: 7th July 2010, 04:59
  4. making new project qt4
    By !Ci in forum Qt Programming
    Replies: 1
    Last Post: 18th June 2009, 14:32
  5. Need help making plugin
    By vieraci in forum Qt Programming
    Replies: 10
    Last Post: 24th September 2007, 14:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.