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. Problem creating a new custom gesture
QtWS25 Last Chance

Problem creating a new custom gesture

Scheduled Pinned Locked Moved General and Desktop
qtcreatorqt5.4gestureqgesturerecogni
10 Posts 2 Posters 4.1k 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.
  • Karen ZurutuzaK Offline
    Karen ZurutuzaK Offline
    Karen Zurutuza
    wrote on last edited by Karen Zurutuza
    #1

    I need to create a new custom gesture with QGestureRecognizer class, but I've a problem when I try to call my gesture class in a widget class.

    QGestureRecognizer CGest = new GestKey;
    Qt::GestureType CGestId = QGestureRecognizer::registerRecognizer(CGest);
    grabGesture(CGestId);

    The error says "cannot allocate an object of abstract type"
    GestKey is a derived class from QGestureRecognizer.

    I'm new programming in Qt Creator, so I've looking for help to create a new custom gesture.
    thanks.

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

      Hi and welcome to devnet,

      Did you reimplement properly the pure virtual recognize function ?

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

      Karen ZurutuzaK 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Did you reimplement properly the pure virtual recognize function ?

        Karen ZurutuzaK Offline
        Karen ZurutuzaK Offline
        Karen Zurutuza
        wrote on last edited by
        #3

        @SGaist Hi and thanks
        I can resolved the problem, but now when i try to call my function in the gesture event I've a new problem :

        bool Llamada::gestureEvent(QGestureEvent *event)
        {
        if(QGesture *key = event->gesture(Qt::CustomGesture))
        KeyTriggered(GestKey *(key));
        return true;
        }

        the error says: "expected primary-expression before '*' token".
        So I can't enter to my function "KeyTriggered"

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

          Hi,

          It's because you have there something that is more of a declaration of a pointer than any thing else;

          What you want to do is to do a cast to a pointer.

          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
          • Karen ZurutuzaK Offline
            Karen ZurutuzaK Offline
            Karen Zurutuza
            wrote on last edited by
            #5

            Hi, so I think that my implementation of the class QGestureRecognizer it's wrong, because in the function:
            Qt::GestureType gestureRecognizer::registerRecognizer(QGestureRecognizer *recognizer)
            {
            }
            Don't create the register. Can you help me to implement the function?

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

              You don't reimplement registerRecognizer. It's a static function that you use to register your own recognizer.

              See this

              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
              • Karen ZurutuzaK Offline
                Karen ZurutuzaK Offline
                Karen Zurutuza
                wrote on last edited by Karen Zurutuza
                #7

                I used this cast:

                bool call::gestureEvent(QGestureEvent *event)
                {
                if (QGesture *key = event->gesture(Qt::CustomGesture))
                KeyTriggered(static_cast<QGestureRecognizer>(key));
                return true;
                }

                but this happend:

                error: invalid static_cast from type 'QGesture*' to type 'QGestureRecognizer*'
                TeclaTriggered(static_cast<QGestureRecognizer*>(tecla));
                ^

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

                  Because key is not a QGestureRecognizer it's a QGesture *. The recognizer's role is to recognize a gesture. You then have to handle the gesture itself. If you wrote a subclass of QGesture then you must cast the pointer accordingly.

                  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
                  • Karen ZurutuzaK Offline
                    Karen ZurutuzaK Offline
                    Karen Zurutuza
                    wrote on last edited by
                    #9

                    I changed my cast to:

                    if (QGesture key = event->gesture(Qt::CustomGesture))
                    KeyTriggered(static_cast<Gestkey
                    >(key));
                    return true;

                    error: invalid static_cast from type 'QGesture*' to type 'GestoTecla*'

                    There is an example of where I can base ?

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

                      Can you show your class and its implementation ?

                      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