<?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[Stop QTimer and Variable scope issue]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">I want to have a QTimer keep running, but sometimes I need to stop and resume this timer.<br />
I have code as below:</p>
<pre><code>void MainWindow::on_pushButton_3_clicked()
{
    QTimer *MainLoopTimer;

    MainLoopTimer = new QTimer();
    connect(MainLoopTimer, SIGNAL(timeout()), this, SLOT(timerUpDate()));
    MainLoopTimer-&gt;start(100);
}

void MainWindow::on_pushButton_7_pressed()
{
     MainLoopTimer-&gt;stop();
}
</code></pre>
<p dir="auto">As you can see, "MainLoopTimer" cannot been seen in "on_pushButton_7_pressed()", so I don't know how to stop this timer.</p>
<p dir="auto">Appreciate for any suggestion,<br />
Thanks,</p>
]]></description><link>https://forum.qt.io/topic/77119/stop-qtimer-and-variable-scope-issue</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 01:01:15 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/77119.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 11 Mar 2017 14:32:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Stop QTimer and Variable scope issue on Sat, 11 Mar 2017 20:02:50 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/hiloshi">@<bdi>Hiloshi</bdi></a> ,</p>
<p dir="auto">As suggested by <a class="plugin-mentions-user plugin-mentions-a" href="/user/flotisable">@<bdi>Flotisable</bdi></a></p>
<p dir="auto">Your <code>QTimer</code> can a var member</p>
<p dir="auto">in your <code>MainWindow.h</code></p>
<pre><code>.
.
.
Private :
QTimer *mTimer;
</code></pre>
<p dir="auto">In your <code>MainWindow.cpp</code></p>
<pre><code>mTimer = new QTimer();
.
.
.
.

void MainWindow::on_pushButton_7_pressed()
{
     mTimer-&gt;stop();
}
.
.
.
</code></pre>
]]></description><link>https://forum.qt.io/post/381455</link><guid isPermaLink="true">https://forum.qt.io/post/381455</guid><dc:creator><![CDATA[mostefa]]></dc:creator><pubDate>Sat, 11 Mar 2017 20:02:50 GMT</pubDate></item><item><title><![CDATA[Reply to Stop QTimer and Variable scope issue on Sat, 11 Mar 2017 14:38:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hiloshi">@<bdi>Hiloshi</bdi></a><br />
I think you can declare <code>MainLoopTimer</code> as <code>MainWindow</code>'s member</p>
]]></description><link>https://forum.qt.io/post/381438</link><guid isPermaLink="true">https://forum.qt.io/post/381438</guid><dc:creator><![CDATA[Flotisable]]></dc:creator><pubDate>Sat, 11 Mar 2017 14:38:26 GMT</pubDate></item></channel></rss>