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.
  • K Offline
    K Offline
    Karen Zurutuza
    wrote on 8 Sept 2015, 16:12 last edited by Karen Zurutuza 9 Aug 2015, 16:17
    #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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Sept 2015, 19:55 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

      K 1 Reply Last reply 11 Sept 2015, 18:46
      0
      • S SGaist
        8 Sept 2015, 19:55

        Hi and welcome to devnet,

        Did you reimplement properly the pure virtual recognize function ?

        K Offline
        K Offline
        Karen Zurutuza
        wrote on 11 Sept 2015, 18:46 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 11 Sept 2015, 22:12 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
          • K Offline
            K Offline
            Karen Zurutuza
            wrote on 15 Sept 2015, 18:13 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 15 Sept 2015, 19:25 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
              • K Offline
                K Offline
                Karen Zurutuza
                wrote on 17 Sept 2015, 19:19 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
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 17 Sept 2015, 19:34 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
                  • K Offline
                    K Offline
                    Karen Zurutuza
                    wrote on 21 Sept 2015, 19:14 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
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 21 Sept 2015, 20:52 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

                      5/10

                      15 Sept 2015, 18:13

                      • Login

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