Example on faking tap gesture on a desktop app



  • Just yesterday a team mate asked me how to fake a gesture event on a desktop, say by clicking on a button, and I quickly wrote "this":http://developer.qt.nokia.com/wiki/TapGestureExampleOnDesktop example using Qt Designer form, a push button when clicked sends a tap gesture



  • @void MainWindow::gest()
    {
    QTapGesture tapGes;
    tapGes.setPosition(QPointF(5,5));
    QList<QGesture *> tapGesTureList;
    tapGesTureList.append(&tapGes);
    QGestureEvent event(tapGesTureList);
    QCoreApplication::sendEvent(this, &event);
    }@

    Are you sure that pointer on the tapGes will be alive? May be next better:

    @void MainWindow::gest()
    {
    QTapGesture *tapGes = new QTapGesture(this);
    tapGes->setPosition(QPointF(5,5));
    QList<QGesture *> tapGesTureList;
    tapGesTureList.append(tapGes);
    QGestureEvent event(tapGesTureList);
    QCoreApplication::sendEvent(this, &event);
    }@



  • that example was just to show how to mimic a gesture, and also agree with you that, if required, using a pointer there will keep it alive :)



  • chetankjain, yes:) but, unfortunately, I understood, ~QGestureEvent does not delete pointers on QTapGesture and they all will be accumulated in the application memory and will be deleted only when MainWindow is destroyed.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.