Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Touch anywhere to launch an application
Forum Updated to NodeBB v4.3 + New Features

Touch anywhere to launch an application

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 3 Posters 1.7k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    Hprasath
    wrote on last edited by
    #1

    Hello all,

    I need to develop a QT application for a embedded device where if i tap anywhere on the screen 5 times(just an example) within a specific time interval, I should be able to launch another application.

    What is the best way to get the touch event notification in my application ? The criteria to launch the application could also be a long press event ? Does QT support capturing long press events ?

    I am using QT embedded version 4.6.0 on a ARM based target board.

    Regards,
    Hari Prasath

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zhxt
      wrote on last edited by
      #2

      Yes, Qt can do both of them.
      There is one way, but not the best way, I think.

      • Specific times press:

      Reimplement mousePressEvent and mouseReleaseEvent.

      Use a self increasing counter to count times of pressed in mouseReleaseEvent. Check if it reached the specific times. If reached, do what you want to do there.

      Use a timer to garantee time interval. Start the timer in mousePressEvent when first tap, Stop the timer and clear the counter when time out.

      some code snap:
      @
      #include "widget.h"
      #include "ui_widget.h"

      Widget::Widget(QWidget *parent) :
      QWidget(parent),
      ui(new Ui::Widget),
      isPressed(false),
      timesOfPressed(0),
      isFistPressed(true),
      isTimerTimeout(false)
      {
      ui->setupUi(this);

      timer = new QTimer(this);
      timer->setInterval(2000);
      connect(timer, SIGNAL(timeout()),this, SLOT(pressTimeOut()));
      

      }

      Widget::~Widget()
      {
      delete ui;
      }

      void Widget::mousePressEvent(QMouseEvent *event)
      {
      if(event->button() == Qt::LeftButton) {
      isPressed = true;
      if (isFistPressed) {
      isFistPressed = false;
      timer->start();
      isTimerTimeout = false;
      }
      }
      }

      void Widget::mouseReleaseEvent(QMouseEvent *event)
      {
      if (event->button() == Qt::LeftButton && isPressed) {
      timesOfPressed++;
      isPressed = false;
      checkPressed();
      }
      }

      void Widget::checkPressed()
      {
      qDebug() << "You have pressed: " << timesOfPressed << "times";

      if (timesOfPressed == 5) {
          timesOfPressed = 0;
          timer->stop();
          isFistPressed = true;
      
          qDebug() << "Finally get here, do something...";
          // call another application with QProcess.
      }
      
      if (isTimerTimeout) {
          timesOfPressed = 0;
          qDebug() << "This round already time out, clear counter ";
      }
      

      }

      void Widget::pressTimeOut()
      {
      qDebug() << "This round time out,recounting.";
      timer->stop();
      isTimerTimeout = true;
      timesOfPressed = 0;
      isFistPressed = true;
      }
      @

      • Long time press:

      Start a timer in mousePressEvent.

      Stop the timer in mouseReleaseEvent.

      Once the timer time out, stop the timer and do what you want to do.

      some code snap:
      @
      ...
      longPressTimer = new QTimer(this);
      longPressTimer->setInterval(1000);
      connect(longPressTimer, SIGNAL(timeout()), this, SLOT(doSomething()));
      ...

      void QWidget::mousePressEvent(QMouseEvent *event)
      {
      if (event->button() == Qt::LeftButton) {
      longPressTimer->start();
      }
      }

      void QWidget::mouseReleaseEvent(QMouseEvent *event)
      {
      if (event->button() == Qt::LeftButton) {
      longPressTimer->stop();
      }
      }

      void QWidget::doSomething()
      {
      longPressTimer->stop();
      // something...
      }
      @

      Qt Developer

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aabc
        wrote on last edited by
        #3

        Do you want to do it with QML or with QT ?

        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