<?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[[solved]: Global parameter]]></title><description><![CDATA[<p dir="auto">Hi..<br />
I want to ask about global parameter in Qt.<br />
I have a class that have a method with 'count' variable. For the time being this 'count' I placed on private.</p>
<p dir="auto">In the mainwindow.cpp, I create an object of that class every 200ms.<br />
I cannot detect if the count reaches 3 (count==3) because I thought that it become 0 when the object created every 200ms.<br />
Please help where should I place this global parameter so that I can detect when the count reaches 3.<br />
Thanks</p>
]]></description><link>https://forum.qt.io/topic/18247/solved-global-parameter</link><generator>RSS for Node</generator><lastBuildDate>Mon, 09 Mar 2026 12:28:20 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/18247.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 13 Jul 2012 04:57:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [solved]: Global parameter on Tue, 17 Jul 2012 05:23:19 GMT]]></title><description><![CDATA[<p dir="auto">Do not mention it</p>
]]></description><link>https://forum.qt.io/post/144696</link><guid isPermaLink="true">https://forum.qt.io/post/144696</guid><dc:creator><![CDATA[Wilk]]></dc:creator><pubDate>Tue, 17 Jul 2012 05:23:19 GMT</pubDate></item><item><title><![CDATA[Reply to [solved]: Global parameter on Tue, 17 Jul 2012 05:20:52 GMT]]></title><description><![CDATA[<p dir="auto">It works, no error message again. And the count run well. Many thanks...<br />
Thank you very very much...:)</p>
]]></description><link>https://forum.qt.io/post/144694</link><guid isPermaLink="true">https://forum.qt.io/post/144694</guid><dc:creator><![CDATA[romeo.rbw]]></dc:creator><pubDate>Tue, 17 Jul 2012 05:20:52 GMT</pubDate></item><item><title><![CDATA[Reply to [solved]: Global parameter on Tue, 17 Jul 2012 04:26:03 GMT]]></title><description><![CDATA[<p dir="auto">Yep, wrong code.<br />
The right one:<br />
mylaserclick.cpp:<br />
@<br />
#include "mylaserclick.h"</p>
<p dir="auto">unsigned int MyLaserClick::ready_klik=0;<br />
unsigned int MyLaserClick::count=0;</p>
<p dir="auto">/* ... */<br />
@</p>
<p dir="auto">And delete 9 and 10 lines from main.cpp.</p>
]]></description><link>https://forum.qt.io/post/144688</link><guid isPermaLink="true">https://forum.qt.io/post/144688</guid><dc:creator><![CDATA[Wilk]]></dc:creator><pubDate>Tue, 17 Jul 2012 04:26:03 GMT</pubDate></item><item><title><![CDATA[Reply to [solved]: Global parameter on Tue, 17 Jul 2012 04:21:28 GMT]]></title><description><![CDATA[<p dir="auto">Hi...<br />
yes may be there is something wrong in my code, here is the code, please give suggestion:</p>
<p dir="auto">mylaserclick.h:</p>
<p dir="auto">@<br />
#ifndef MYLASERCLICK_H<br />
#define MYLASERCLICK_H</p>
<p dir="auto">#include &lt;QObject&gt;<br />
#include &lt;opencv2/core/core.hpp&gt;</p>
<p dir="auto">using namespace std;<br />
using namespace cv;</p>
<p dir="auto">class MyLaserClick : public QObject<br />
{<br />
Q_OBJECT<br />
public:<br />
explicit MyLaserClick(bool inspace, bool laser_on, QObject *parent = 0);</p>
<p dir="auto">signals:</p>
<p dir="auto">public slots:<br />
bool cek_click();</p>
<p dir="auto">private:<br />
bool inspace;<br />
bool on;</p>
<pre><code>static unsigned int ready_klik;
static unsigned int count;
</code></pre>
<p dir="auto">};</p>
<p dir="auto">#endif // MYLASERCLICK_H<br />
@</p>
<p dir="auto">mylaserclick.cpp:<br />
@<br />
#include "mylaserclick.h"</p>
<p dir="auto">MyLaserClick::MyLaserClick(bool inspace, bool laser_on, QObject *parent) :<br />
QObject(parent)<br />
{<br />
this-&gt;inspace = inspace;<br />
this-&gt;on = laser_on;</p>
<p dir="auto">}</p>
<p dir="auto">bool MyLaserClick::cek_click()<br />
{<br />
if (inspace==true &amp;&amp; on==true &amp;&amp; ready_klik != 2)<br />
ready_klik=1;</p>
<pre><code>if (on==false &amp;&amp; ready_klik==1 &amp;&amp; inspace==true){
    ready_klik=2;
    count= count+1;
}
if (count==1 &amp;&amp; inspace==false){     
    ready_klik=0;
    count=0;
}

if (on==true &amp;&amp; ready_klik==2 &amp;&amp; inspace==true){
    count = count+1;
}

if (count==2){
    return true;
    count=0;
    ready_klik=0;
}
</code></pre>
<p dir="auto">else<br />
return false;<br />
}</p>
<p dir="auto">EDIT1:  :) I modify by change the 'return true;' to the last line<br />
if (count==2){<br />
count=0;<br />
ready_klik=0;<br />
return true;<br />
}</p>
<p dir="auto">@</p>
<p dir="auto">mainwindow.cpp:<br />
@<br />
....<br />
MyLaserClick *laserklik;<br />
laserklik = new MyLaserClick(inspace,on);<br />
laser_click_inspace = laserklik-&gt;cek_click();<br />
....<br />
@</p>
<p dir="auto">main.cpp:<br />
@<br />
#include &lt;QtGui/QApplication&gt;<br />
#include "mainwindow.h"</p>
<p dir="auto">int main(int argc, char *argv[])<br />
{<br />
QApplication a(argc, argv);</p>
<pre><code>unsigned int MyLaserClick::ready_klik=0;
unsigned int MyLaserClick::count=0;

MainWindow *dialog = new MainWindow;
dialog-&gt;show();

return a.exec(&amp;#41;;
</code></pre>
<p dir="auto">}<br />
@</p>
<p dir="auto">the error message are:<br />
'MyLaserClick' is not a class or namespace name    main.cpp   line 9</p>
<p dir="auto">'MyLaserClick' is not a class or namespace name    main.cpp   line 10</p>
]]></description><link>https://forum.qt.io/post/144687</link><guid isPermaLink="true">https://forum.qt.io/post/144687</guid><dc:creator><![CDATA[romeo.rbw]]></dc:creator><pubDate>Tue, 17 Jul 2012 04:21:28 GMT</pubDate></item><item><title><![CDATA[Reply to [solved]: Global parameter on Tue, 17 Jul 2012 03:36:45 GMT]]></title><description><![CDATA[<p dir="auto">Hello again.<br />
I'm sorry, but it seems like you're doing something wrong. Because I'm looking at my own code with the same structure. It works. Could you please post code, that doesn't work and compiler output with error?</p>
]]></description><link>https://forum.qt.io/post/144684</link><guid isPermaLink="true">https://forum.qt.io/post/144684</guid><dc:creator><![CDATA[Wilk]]></dc:creator><pubDate>Tue, 17 Jul 2012 03:36:45 GMT</pubDate></item><item><title><![CDATA[Reply to [solved]: Global parameter on Tue, 17 Jul 2012 03:27:35 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for reply...<br />
I already try it, I tried adding unsigned int MyClass::count=0, in mainwindow.cpp, it did not work. And neither in main.cpp.<br />
Is there any other solution for Global parameter?<br />
thanks in advance</p>
]]></description><link>https://forum.qt.io/post/144680</link><guid isPermaLink="true">https://forum.qt.io/post/144680</guid><dc:creator><![CDATA[romeo.rbw]]></dc:creator><pubDate>Tue, 17 Jul 2012 03:27:35 GMT</pubDate></item><item><title><![CDATA[Reply to [solved]: Global parameter on Fri, 13 Jul 2012 07:31:48 GMT]]></title><description><![CDATA[<p dir="auto">Sorry, my fault. Change to @static unsigned int count@ and in you .cpp file write <a class="plugin-mentions-user plugin-mentions-a" href="/user/unsigned">@<bdi>unsigned</bdi></a> int Your_Class::count = 0.@</p>
]]></description><link>https://forum.qt.io/post/144308</link><guid isPermaLink="true">https://forum.qt.io/post/144308</guid><dc:creator><![CDATA[Wilk]]></dc:creator><pubDate>Fri, 13 Jul 2012 07:31:48 GMT</pubDate></item><item><title><![CDATA[Reply to [solved]: Global parameter on Fri, 13 Jul 2012 07:26:20 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for your reply,<br />
I tried but there is a message:<br />
'  ..only static const integral data members can be initialized within a class'</p>
<p dir="auto">I change the parameter to</p>
<p dir="auto">static unsigned int count;</p>
<p dir="auto">the message become: ' unresolved external symbol...'</p>
]]></description><link>https://forum.qt.io/post/144307</link><guid isPermaLink="true">https://forum.qt.io/post/144307</guid><dc:creator><![CDATA[romeo.rbw]]></dc:creator><pubDate>Fri, 13 Jul 2012 07:26:20 GMT</pubDate></item><item><title><![CDATA[Reply to [solved]: Global parameter on Fri, 13 Jul 2012 05:16:24 GMT]]></title><description><![CDATA[<p dir="auto">Hello.<br />
One of the possible ways of achieving what you want is to make count a static private field, increment it in constructor and decrement it in destructor:<br />
@<br />
class Your_Class {<br />
private:<br />
static unsigned int count = 0;<br />
public:<br />
Your_Class () {<br />
count++;<br />
}<br />
~Your_Class () {<br />
count--;<br />
}<br />
}<br />
@<br />
But I think it's not a good solution:</p>
<h1>It's not thread safe.</h1>
<h1>You should watch out for temp objects.</h1>
]]></description><link>https://forum.qt.io/post/144297</link><guid isPermaLink="true">https://forum.qt.io/post/144297</guid><dc:creator><![CDATA[Wilk]]></dc:creator><pubDate>Fri, 13 Jul 2012 05:16:24 GMT</pubDate></item></channel></rss>