Important: Please read the Qt Code of Conduct -

I am getting hang when drop event during file loading?

  • 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.


    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());
    else {
    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.

  • Lifetime Qt Champion


    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).

  • @SGaist could u please write some piece of code

  • @SGaist emit signal are present in drag.cpp class and signal and slot are present in mainwindow.cpp class. Then who could i pass the QTimer in it?

  • Lifetime Qt Champion

    Please take a look at the method documentation.

  • Moderators

    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.

  • @J.Hilk thank you @J-Hilk ... this one working for me...

  • Banned

    This post is deleted!

Log in to reply