Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannot show modal dialog or block in QFileSystemModel::dropMimeData() or QTreeView::dropEvent() in Qt 6 during drag and drop
Forum Updated to NodeBB v4.3 + New Features

Cannot show modal dialog or block in QFileSystemModel::dropMimeData() or QTreeView::dropEvent() in Qt 6 during drag and drop

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 110 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PuskasAlex
    wrote on last edited by
    #1

    Description:

    In Qt 5.15 it was possible to show a modal dialog (e.g., QMessageBox::question()) directly inside QFileSystemModel::dropMimeData() or in QTreeView::dropEvent() during a drag and drop operation to ask the user for confirmation before accepting the drop.

    Since upgrading to Qt 6 (tested on Qt 6.8), attempting to show a modal dialog or block the event processing in these functions results in an application crash. This breaks the workflow for applications that need explicit user confirmation before accepting a drop.

    Steps to reproduce:

    1. Override QTreeView::dropEvent().
    2. In this override, display a modal QMessageBox::question() dialog to confirm the drop.
    3. Run the application.
    4. Perform a drag and drop operation.

    Expected behavior:

    The dialog should appear.
    Depending on the user response, the drop is accepted or rejected.

    Actual behavior:

    The application crashes immediately when the dialog is shown during dropEvent().

    Code snippet:

    class MyTreeView : public QTreeView {
    public:
        using QTreeView::QTreeView;
    
    protected:
        void dropEvent(QDropEvent* event) override {
            if (event->mimeData()->hasUrls()) {
                if (QMessageBox::question(this, "title", "body") == QMessageBox::Yes) {
                    QTreeView::dropEvent(event);
                } else {
                    event->ignore();
                }
            } else {
                event->ignore();
            }
        }
    };
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        QFileSystemModel *model = new QFileSystemModel();
        model->setRootPath(QDir::homePath());
        model->setReadOnly(false);
    
        MyTreeView *view = new MyTreeView();
        view->setModel(model);
        view->setRootIndex(model->index(QDir::homePath()));
        view->setDragEnabled(true);
        view->setAcceptDrops(true);
        view->setDropIndicatorShown(true);
        view->setWindowTitle("Drop Test Qt 6");
        view->resize(800, 600);
        view->show();
    
        return app.exec();
    }
    

    This application crashes using Qt 6.8 but not using Qt 5.15.2 on Windows.

    Environment:

    Qt Version: 6.8 (also occurs on 6.5)
    OS: Windows 10 x32
    Compiler: MSVC 2022

    Questions:

    Do you have any recommendation or workaround for this issue?
    How can this issue be avoided in Qt 6?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      Zbigniew-Sch
      wrote on last edited by
      #2

      @PuskasAlex said in Cannot show modal dialog or block in QFileSystemModel::dropMimeData() or QTreeView::dropEvent() in Qt 6 during drag and drop:

      QTreeView::dropEvent(event);

      Hi,

      Delete QTreeView::dropEvent(event) and everything will work fine:

      if (QMessageBox::question(this, "title", "body") == QMessageBox::Yes)
      event->accept();;
      else
      event->ignore();

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved