Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Event Replay
Forum Updated to NodeBB v4.3 + New Features

Qt Event Replay

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 1.4k Views 2 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.
  • M Offline
    M Offline
    Matt86
    wrote on last edited by
    #1

    I'm trying to replay stored events using QApplication::postEvent(). To do this you need to know what QObject to send the event to. This is information that will need to be serialized along with the QEvent information. One way to do this is to assign names to all the objects in the program by calling QObject::setObjectName(). The issue with this method is that it doesn't like to play nice with QTableView when editing cells or QTreeWidget for drag and drop. It appears the event replay works well with other objects. Do you recommend another way to find the correct widget to send the events to?

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

      Hi and welcome to devnet,

      How are you currently "recording" these events ?

      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
      0
      • M Offline
        M Offline
        Matt86
        wrote on last edited by
        #3

        I'm creating deep copies of the events and storing them in a vector and replaying the events via postEvent().

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

          Then how do you make these copies ?

          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
          0
          • M Offline
            M Offline
            Matt86
            wrote on last edited by
            #5

            unique_ptr<QEvent> copyEvent(const QEvent * ev) {
            unique_ptr<QEvent> eventCopy;

            if(dynamic_cast<const QMouseEvent *>(ev)) {
              eventCopy = make_unique<QMouseEvent>(
                static_cast<const QMouseEvent&>(*ev));
            }
            else if(dynamic_cast<const QContextMenuEvent *>(ev)) {
              eventCopy = make_unique<QContextMenuEvent>(
                static_cast<const QContextMenuEvent&>(*ev));  
            }
            else if(dynamic_cast<const QTabletEvent *>(ev)) {
              eventCopy = make_unique<QTabletEvent>(
                static_cast<const QTabletEvent&>(*ev));  
            }
            else if(dynamic_cast<const QDropEvent *>(ev)) {
              eventCopy = make_unique<QDropEvent>(
                static_cast<const QDropEvent&>(*ev));  
            }
            else if(dynamic_cast<const QDragEnterEvent *>(ev)) {
              eventCopy = make_unique<QDragEnterEvent>(
                static_cast<const QDragEnterEvent&>(*ev));  
            }
            else if(dynamic_cast<const QDragLeaveEvent *>(ev)) {
              eventCopy = make_unique<QDragLeaveEvent>(
                static_cast<const QDragLeaveEvent&>(*ev));  
            }
            else if(dynamic_cast<const QDragMoveEvent *>(ev)) {
              eventCopy = make_unique<QDragMoveEvent>(
                static_cast<const QDragMoveEvent&>(*ev));  
            }
            
            return eventCopy;
            

            }
            }

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

              And where exactly are you calling that code in your application ?

              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
              0
              • M Offline
                M Offline
                Matt86
                wrote on last edited by
                #7

                void UIEventRecorder::replayEvent(void) {
                const UIEvent& ithEvent = recordedEvents[replayRecordedEventIndex++];

                QStringList path = QString::fromStdString(ithEvent.getObjectName()).
                split("/", QString::KeepEmptyParts);

                if(path.isEmpty()) {
                return;
                }

                QList<QObject*> objects = mainWndHandle->findChildren<QObject*>(path.last());

                for(const auto& it: objects) {
                if(it->metaObject()->className() == ithEvent.getClassName()
                && UIUtil::getObjectPathName(it) == ithEvent.getObjectName()) {

                  // this will post the event to replay and won't block
                  qApp->postEvent(it, copyEvent(ithEvent.getEvent()).release());
                  break;
                }
                

                }

                // we replayed all the events
                // let's return
                if(replayRecordedEventIndex >= recordedEvents.size()) {
                replayRecordedEventIndex = 0;
                return;
                }

                // time between events
                int delta = recordedEvents[replayRecordedEventIndex].getTimeOffset() -
                recordedEvents[replayRecordedEventIndex - 1].getTimeOffset();

                // set the interval to call the next event
                timer->setInterval(delta > 0 ? delta : 0);
                timer->start();

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

                  Are you doing the recording in an event filter ?

                  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
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved