Qt World Summit: Submit your Presentation

Problem creating a new custom gesture

  • 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);

    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.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you reimplement properly the pure virtual recognize function ?

  • @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"

  • Lifetime Qt Champion


    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.

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

  • Lifetime Qt Champion

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

    See this

  • I used this cast:

    bool call::gestureEvent(QGestureEvent *event)
    if (QGesture *key = event->gesture(Qt::CustomGesture))
    return true;

    but this happend:

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

  • Lifetime Qt Champion

    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.

  • I changed my cast to:

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

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

    There is an example of where I can base ?

  • Lifetime Qt Champion

    Can you show your class and its implementation ?