Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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.

    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.


  • Lifetime Qt Champion

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



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

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



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


  • Banned

    This post is deleted!

Log in to reply