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. [Solved again] Post a QGestureEvent to a QStateMachine
QtWS25 Last Chance

[Solved again] Post a QGestureEvent to a QStateMachine

Scheduled Pinned Locked Moved General and Desktop
state machineeventposteventgesturesstatemachine
8 Posts 2 Posters 3.0k Views
  • 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
    Malte J
    wrote on last edited by Malte J
    #1

    Hello everybody,

    i have a problem when posting QGestureEvents to a QStateMachine.
    I implemented custom gesture recognizers, which a correctly registered and now i am receiving QGestureEvents in my application. I then do some processing and afterwards i would like to post one gesture event to my state machine.

    QList<QGesture *> newGestureList;
    newGestureList.append(g);
    if (mp_stateMachine){
    	QGestureEvent *ev = new QGestureEvent(newGestureList);
    	mp_stateMachine->postEvent(ev);
    }
    

    So far so good. For Gestures with the state Qt::GestureStarted and Qt::GestureUpdated everything works fine.

    Now the problem:
    When the gesture has the state Qt::GestureFinished or Qt::GestureCancelled, it gets resetted by Qt, so that in custom transition, i receive the events, but the gestures have the state Qt::NoGesture. That is very critical to me since i need to check the state afterwards.

    I found out, that in QGestureManager.cpp the cancelled and finished gestures are resetted:

        // reset gestures that ended
        QSet<QGesture *> endedGestures =
                finishedGestures + canceledGestures + undeliveredGestures + maybeToCanceledGestures;
        foreach (QGesture *gesture, endedGestures) {
            recycle(gesture);
            m_gestureTargets.remove(gesture);
        } 
    

    But I don't know why and how to solve my problem.

    Any ideas are welcome!

    Thank you in advance,
    MalteJ

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

      Hi and welcome to devnet,

      Shouldn't you rather decouple the two ? Handle the gesture in your widget, then send a custom event to your state machine so the machine doesn't need to know QGestureEvent and thus you can also change easily what triggers that custom event.

      Hope it helps

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

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Shouldn't you rather decouple the two ? Handle the gesture in your widget, then send a custom event to your state machine so the machine doesn't need to know QGestureEvent and thus you can also change easily what triggers that custom event.

        Hope it helps

        M Offline
        M Offline
        Malte J
        wrote on last edited by Malte J
        #3

        @SGaist Thank you for your fast answer.

        In fact, I implemented custom gestures, which contain all important information for the decision.
        My custom Transition class called GestureTransition triggers according to the specified gesture event.

        Could I implement a custom event holding a QGesture object? If yes, how?

        Thanks, Malte

        Edit: I think i got it, subclassing QEvent was not that hard ;) Thank you for the idea!

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Malte J
          wrote on last edited by
          #4

          Okay... i have to reopen this issue.

          like @SGaist proposed, I want to post a custom event to my state machine. However, I want this event to hold an instance of the causing QGesture object. Sadly, i see no way of copying such an object, and if I use a pointer, it is the same object that gets killed by Qt in the QGestureManager as said above..

          Any ideas to solve this? I have like 8 custom gesture classes that hold different information, which are all subclasses of QGesture (for the information of the QGestureState). And I don't want to miss that..

          PS: QGesture(const QGesture &) constructor does not work. It does not copy the state and properties...

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

            QGesture is a QObject thus it can't be copied.

            I'd make these information separated objects (struct or class) and use them with your new events. This will avoid passing QGesture objects around.

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

            M 1 Reply Last reply
            0
            • SGaistS SGaist

              QGesture is a QObject thus it can't be copied.

              I'd make these information separated objects (struct or class) and use them with your new events. This will avoid passing QGesture objects around.

              M Offline
              M Offline
              Malte J
              wrote on last edited by
              #6

              @SGaist So basically duplicating all the functionality provided by QGesture because i can't copy the objects? That doesn't sound very convenient to me.

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

                We might be misunderstanding each other. Is it correct that you have some custom data inside your custom gestures ?
                If so, what I'm suggesting is to make these custom data easily accessible and copy them to the events you send to the state machine.

                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
                  Malte J
                  wrote on last edited by
                  #8

                  Yes that is correct. Every of the 8 custom gestures defines its own set of data in addition to the QGestureState, which is set by the according gesture recognizer.

                  I now implemented an abstract superclass for all these gestures with a method getGestureData(). This method basically wraps all the data in a QMap<QString,QVariant> to make a general gesture treatment possible. The custom event GestureEvent now takes gesture type, the Qt::GestureState and the mentioned gesture data map.
                  It was a little bit circumstantial, but now it works.

                  Thanks again,
                  Malte

                  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