I am getting hang when drop event during file loading?
Solved
Game Development
-
I am using the drag and drop functionality inside m project. i am getting hang when i will drop image inside the viewer because file loading take some file to load it.
drop.cpp
void drop::dropEvent(QDropEvent *event) { const QMimeData *mimeData = event->mimeData(); int row,col; QImage image = qvariant_cast<QImage>(event->mimeData()->imageData()); QListWidget *child = static_cast<QListWidget*>(childAt(event->pos())); if (mimeData->hasFormat("application/x-qabstractitemmodeldatalist")) { QByteArray encoded = mimeData->data("application/x-qabstractitemmodeldatalist"); QDataStream stream(&encoded, QIODevice::ReadOnly); while (!stream.atEnd()) { QMap<int, QVariant> roleDataMap; stream >> row >> col >> roleDataMap ; QIcon icon = roleDataMap.value(1).value<QIcon>(); m_pixmap = icon.pixmap(icon.availableSizes().first()); update(); } event->acceptProposedAction(); } else { event->ignore(); } emit DragDropObject(row); // here i am calling the loading function }
So my question is how can i release the drop event before calling the loading of file.
-
Hi,
You could use a single shot QTimer with 0 as timeout value and trigger your method in the slot connected to it (or a lambda).
-
Please take a look at the method documentation.
-
@amarism
to give you a 2nd option, you could, give your connect statement - the one in mainwindow.cpp -Qt::QueuedConnection
as a 5th parameter, that will have the same effect as a singleShot QTimer with a timeout of 0 but with slightly less overhead.