Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. I am getting hang when drop event during file loading?
Forum Updated to NodeBB v4.3 + New Features

I am getting hang when drop event during file loading?

Scheduled Pinned Locked Moved Solved Game Development
8 Posts 4 Posters 1.6k 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.
  • A Offline
    A Offline
    amarism
    wrote on last edited by amarism
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 2 Replies Last reply
      0
      • SGaistS SGaist

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

        A Offline
        A Offline
        amarism
        wrote on last edited by
        #3

        @SGaist could u please write some piece of code

        1 Reply Last reply
        0
        • SGaistS SGaist

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

          A Offline
          A Offline
          amarism
          wrote on last edited by
          #4

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

          J.HilkJ 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Please take a look at the method documentation.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • A amarism

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

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

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


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              A 1 Reply Last reply
              2
              • J.HilkJ J.Hilk

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

                A Offline
                A Offline
                amarism
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  cemlysoy
                  Banned
                  wrote on last edited by
                  #8
                  This post is deleted!
                  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