<?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[bool is converted to another value in signal-slot mechanism?]]></title><description><![CDATA[<p dir="auto">I have a class that emits a signal:</p>
<pre><code>bool myClass::eventFilter(QObject *object, QEvent *event) {
    if(event-&gt;type() == QEvent::MouseButtonRelease) {
        auto o = static_cast&lt;someClass *&gt;(object);
        emit clicked(o-&gt;getName(), o-&gt;isValid())
        return true;
    }

    return QScrollArea::eventFilter(object, event);
}
</code></pre>
<p dir="auto"><em>clicked()</em>'s declaration:</p>
<pre><code>void clicked(const QString &amp;name, bool isValid);
</code></pre>
<p dir="auto">and I have another class where I do a connect:</p>
<pre><code>QObject::connect(ob, SIGNAL(clicked(const QString &amp;, bool)), SLOT(load(const QString &amp;, bool)));
</code></pre>
<p dir="auto">in load I print the passed values and I got 80 and 64 for bool:</p>
<pre><code>void otherClass::load(const QString &amp;name, bool isValid) {
    std::cout &lt;&lt; name.toStdString() &lt;&lt; ' ' &lt;&lt;  isValid &lt;&lt; std::endl;
}
</code></pre>
<p dir="auto">When I print the values from <em><strong>eventFilter()</strong></em>, I still get 80 for bool. However, if I print the value of isValid() from another place, I get correct 0 or 1.</p>
<p dir="auto">Why is this? and how can I get correct bool values in my slot?</p>
<p dir="auto"><em>[Edit: fixed markup ~~ @Wieland]</em></p>
]]></description><link>https://forum.qt.io/topic/83909/bool-is-converted-to-another-value-in-signal-slot-mechanism</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 11:40:32 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/83909.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Oct 2017 18:24:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to bool is converted to another value in signal-slot mechanism? on Thu, 05 Oct 2017 20:45:44 GMT]]></title><description><![CDATA[<p dir="auto">i know, i know! my app crashed too :( then i checked the return value and everything is okay now!</p>
<p dir="auto">p.s. everyone should learn from their own pain (i mean the crash) ;)</p>
]]></description><link>https://forum.qt.io/post/419026</link><guid isPermaLink="true">https://forum.qt.io/post/419026</guid><dc:creator><![CDATA[user4592357]]></dc:creator><pubDate>Thu, 05 Oct 2017 20:45:44 GMT</pubDate></item><item><title><![CDATA[Reply to bool is converted to another value in signal-slot mechanism? on Thu, 05 Oct 2017 20:26:11 GMT]]></title><description><![CDATA[<p dir="auto">And <em>always</em> check the return of <code>qobject_cast&lt;&gt;</code> as per<br />
<a href="https://forum.qt.io/topic/83689/setmodeldata-crashes-program/14">https://forum.qt.io/topic/83689/setmodeldata-crashes-program/14</a> onward :)</p>
]]></description><link>https://forum.qt.io/post/419016</link><guid isPermaLink="true">https://forum.qt.io/post/419016</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 05 Oct 2017 20:26:11 GMT</pubDate></item><item><title><![CDATA[Reply to bool is converted to another value in signal-slot mechanism? on Thu, 05 Oct 2017 20:21:09 GMT]]></title><description><![CDATA[<p dir="auto">my bad... i hadn't installed the event filter on the watched object. everything works now.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> thanks for the advice. changed to qobject_cast. well at least i learned that from my stupid mistake</p>
]]></description><link>https://forum.qt.io/post/419014</link><guid isPermaLink="true">https://forum.qt.io/post/419014</guid><dc:creator><![CDATA[user4592357]]></dc:creator><pubDate>Thu, 05 Oct 2017 20:21:09 GMT</pubDate></item><item><title><![CDATA[Reply to bool is converted to another value in signal-slot mechanism? on Thu, 05 Oct 2017 19:57:15 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">One thing, you should use <a href="http://doc.qt.io/qt-5/qobject.html#qobject_cast" target="_blank" rel="noopener noreferrer nofollow ugc">qobject_cast</a> and not static_cast when dealing with QObject based classes.</p>
<p dir="auto">Did you try to print what you emit before calling emit ?</p>
]]></description><link>https://forum.qt.io/post/419002</link><guid isPermaLink="true">https://forum.qt.io/post/419002</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 05 Oct 2017 19:57:15 GMT</pubDate></item><item><title><![CDATA[Reply to bool is converted to another value in signal-slot mechanism? on Thu, 05 Oct 2017 19:40:54 GMT]]></title><description><![CDATA[<p dir="auto">@Wieland</p>
<p dir="auto">is just returns a bool data member:</p>
<pre><code>bool someClass::isValid() const {
    return m_isValid;
}
</code></pre>
<p dir="auto">and <em>m_isValid</em> is set in the constructor</p>
<p dir="auto">EDIT: this is weird. there's another thing that makes me bowl my eyes. getName() and isValid() are const member fucntions, and as i found out they are the reason the program works wrong, 80? what is 80? i tried to emit clicked(QString("1234"), false); and that time i get 0 printed correctly.</p>
<p dir="auto">so what is the reason for this? can't i call something during emitting a signal???</p>
]]></description><link>https://forum.qt.io/post/418991</link><guid isPermaLink="true">https://forum.qt.io/post/418991</guid><dc:creator><![CDATA[user4592357]]></dc:creator><pubDate>Thu, 05 Oct 2017 19:40:54 GMT</pubDate></item><item><title><![CDATA[Reply to bool is converted to another value in signal-slot mechanism? on Thu, 05 Oct 2017 18:59:36 GMT]]></title><description><![CDATA[<p dir="auto">Hi! Please show us the declaration of <code>someClass::isValid</code>.</p>
]]></description><link>https://forum.qt.io/post/418989</link><guid isPermaLink="true">https://forum.qt.io/post/418989</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 05 Oct 2017 18:59:36 GMT</pubDate></item></channel></rss>