<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Touch anywhere to launch an application]]></title><description><![CDATA[<p dir="auto">Hello all,</p>
<p dir="auto">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.</p>
<p dir="auto">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 ?</p>
<p dir="auto">I am using QT embedded version 4.6.0 on a ARM based target board.</p>
]]></description><link>https://forum.qt.io/topic/17073/touch-anywhere-to-launch-an-application</link><generator>RSS for Node</generator><lastBuildDate>Wed, 12 Aug 2026 02:19:21 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/17073.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 27 May 2012 00:01:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Touch anywhere to launch an application on Sun, 03 Jun 2012 06:49:27 GMT]]></title><description><![CDATA[<p dir="auto">Do you want to do it with QML or with QT ?</p>
]]></description><link>https://forum.qt.io/post/140664</link><guid isPermaLink="true">https://forum.qt.io/post/140664</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sun, 03 Jun 2012 06:49:27 GMT</pubDate></item><item><title><![CDATA[Reply to Touch anywhere to launch an application on Fri, 01 Jun 2012 17:09:54 GMT]]></title><description><![CDATA[<p dir="auto">Yes, Qt can do both of them.<br />
There is one way, but not the best way, I think.</p>
<ul>
<li>Specific times press:</li>
</ul>
<h1>Reimplement mousePressEvent and mouseReleaseEvent.</h1>
<h1>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.</h1>
<h1>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.</h1>
<p dir="auto">some code snap:<br />
@<br />
#include "widget.h"<br />
#include "ui_widget.h"</p>
<p dir="auto">Widget::Widget(QWidget *parent) :<br />
QWidget(parent),<br />
ui(new Ui::Widget),<br />
isPressed(false),<br />
timesOfPressed(0),<br />
isFistPressed(true),<br />
isTimerTimeout(false)<br />
{<br />
ui-&gt;setupUi(this);</p>
<pre><code>timer = new QTimer(this);
timer-&gt;setInterval(2000);
connect(timer, SIGNAL(timeout()),this, SLOT(pressTimeOut()));
</code></pre>
<p dir="auto">}</p>
<p dir="auto">Widget::~Widget()<br />
{<br />
delete ui;<br />
}</p>
<p dir="auto">void Widget::mousePressEvent(QMouseEvent *event)<br />
{<br />
if(event-&gt;button() == Qt::LeftButton) {<br />
isPressed = true;<br />
if (isFistPressed) {<br />
isFistPressed = false;<br />
timer-&gt;start();<br />
isTimerTimeout = false;<br />
}<br />
}<br />
}</p>
<p dir="auto">void Widget::mouseReleaseEvent(QMouseEvent *event)<br />
{<br />
if (event-&gt;button() == Qt::LeftButton &amp;&amp; isPressed) {<br />
timesOfPressed++;<br />
isPressed = false;<br />
checkPressed();<br />
}<br />
}</p>
<p dir="auto">void Widget::checkPressed()<br />
{<br />
qDebug() &lt;&lt; "You have pressed: " &lt;&lt; timesOfPressed &lt;&lt; "times";</p>
<pre><code>if (timesOfPressed == 5) {
    timesOfPressed = 0;
    timer-&gt;stop();
    isFistPressed = true;

    qDebug() &lt;&lt; "Finally get here, do something...";
    // call another application with QProcess.
}

if (isTimerTimeout) {
    timesOfPressed = 0;
    qDebug() &lt;&lt; "This round already time out, clear counter ";
}
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void Widget::pressTimeOut()<br />
{<br />
qDebug() &lt;&lt; "This round time out,recounting.";<br />
timer-&gt;stop();<br />
isTimerTimeout = true;<br />
timesOfPressed = 0;<br />
isFistPressed = true;<br />
}<br />
@</p>
<ul>
<li>Long time press:</li>
</ul>
<h1>Start a timer in mousePressEvent.</h1>
<h1>Stop the timer in mouseReleaseEvent.</h1>
<h1>Once the timer time out, stop the timer and do what you want to do.</h1>
<p dir="auto">some code snap:<br />
@<br />
...<br />
longPressTimer = new QTimer(this);<br />
longPressTimer-&gt;setInterval(1000);<br />
connect(longPressTimer, SIGNAL(timeout()), this, SLOT(doSomething()));<br />
...</p>
<p dir="auto">void QWidget::mousePressEvent(QMouseEvent *event)<br />
{<br />
if (event-&gt;button() == Qt::LeftButton) {<br />
longPressTimer-&gt;start();<br />
}<br />
}</p>
<p dir="auto">void QWidget::mouseReleaseEvent(QMouseEvent *event)<br />
{<br />
if (event-&gt;button() == Qt::LeftButton) {<br />
longPressTimer-&gt;stop();<br />
}<br />
}</p>
<p dir="auto">void QWidget::doSomething()<br />
{<br />
longPressTimer-&gt;stop();<br />
// something...<br />
}<br />
@</p>
]]></description><link>https://forum.qt.io/post/140601</link><guid isPermaLink="true">https://forum.qt.io/post/140601</guid><dc:creator><![CDATA[zhxt]]></dc:creator><pubDate>Fri, 01 Jun 2012 17:09:54 GMT</pubDate></item></channel></rss>