Solved Bug(?) with modal dialog and drag&dop
-
Hi Qt hive,
I have a user interface with dialogs. In one of the dialogs I am using
QListWidgets
to presentQListWidgetItems
that the user can drag&drop from one list to other receiver list.The source code of my dialog looks like this:
[...] DragDialog::DragDialog(QWidget* parent) : QDialog(parent) { setWindowTitle("Drag&Drop Test"); QListWidget* source = new QListWidget(); source->setAlternatingRowColors(true); source->setSelectionMode(QAbstractItemView::SingleSelection); source->setDragEnabled(true); source->setDragDropMode(QAbstractItemView::DragDrop); source->setDefaultDropAction(Qt::MoveAction); source->viewport()->setAcceptDrops(true); source->setDropIndicatorShown(true); // names is a QStringList with the names of US presidents just to fill the list for(auto const name : names) { auto item = new QListWidgetItem(name); item->setToolTip(name); item->setData(Qt::UserRole, name); source->addItem(item); } QListWidget* target1 = new QListWidget(); target1->setAlternatingRowColors(true); target1->setSelectionMode(QAbstractItemView::SingleSelection); target1->setDragEnabled(true); target1->setDragDropMode(QAbstractItemView::DragDrop); target1->setDefaultDropAction(Qt::MoveAction); target1->viewport()->setAcceptDrops(true); target1->setDropIndicatorShown(true); QHBoxLayout* layout = new QHBoxLayout(); layout->addWidget(source); layout->addWidget(target); setLayout(layout); } [...]
And here is the relevant part of the corresponding
main.cpp
:int main(int argc, char* argv) { QApplication app(argc, argv); DragDialog dialog; dialog.show(); app.connect(&app, &QApplication::lastWindowClosed, &app, &QApplication::quit); return app.exec(); }
When I am using
show()
- as in the main.cpp above - to display the dialog, everything works fine and I can drag items from one list to the other and back. However, if I useexec()
, the dialog freezes when I start to move a single item and I have to log in from a different machine to kill the process.Has anybody seen this before and a way out?
I am using a system installation of Qt 5.9.2 on CentOS 7.5 (1804). On a different system, we have been using 5.6 and 5.9.3 and it was no problem.
Thanks!
-
I was able to reduce the code to this snippet that still generates the error on my system:
#include <QtWidgets/QApplication> #include <QtWidgets/QDialog> #include <QtWidgets/QListWidgetItem> #include <QtWidgets/QListWidget> #include <QtWidgets/QVBoxLayout> int main (int argc, char **argv) { QApplication app(argc, argv); QDialog dialog; QListWidget* source = new QListWidget(); source->setDragEnabled(true); new QListWidgetItem("foo", source); new QVBoxLayout(&dialog); dialog.layout()->addWidget (source); return dialog.exec(); }
-
This is an actual bug in 5.9.2, see https://bugreports.qt.io/browse/QTBUG-63968