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);
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. -
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" -
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.
-
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? -
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));
^ -
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))
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 ?
-
Can you show your class and its implementation ?