<?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[problem with chained signal&#x2F;slot connections]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm working on condition classes and this time I have trouble with 'AndCondition', which uses other conditionals.</p>
<p dir="auto">Each conditional works together with ValueModels, which is similar to Qt properties, i.e. a valueModel has a name and a value and issues an event in case of value changes.</p>
<p dir="auto">A <a href="https://github.com/DjangoReinhard/ToolManager/raw/main/sample/ConditionTests-211106.tar.xz" target="_blank" rel="noopener noreferrer nofollow ugc">stripped down testunit</a> is available.</p>
<p dir="auto">Testcase looks like this:</p>
<pre><code>void TestEngine::testAndCondition() {
  ValueModel v0("left", 13);
  ValueModel v1("right", 3);
  GreaterCondition gc(&amp;v0, 20);
  NotCondition     nc(&amp;v1, 3);
  AndCondition     ac(gc, nc);

  connect(&amp;ac, &amp;AbstractCondition::conditionChanged, this, &amp;TestEngine::updateCondition);

  QCOMPARE(result = ac.result(), false);

  qDebug() &lt;&lt; "set v0 to 32";
  v0.setValue(32);

  QCOMPARE(result, false);

  qDebug() &lt;&lt; "set v1 to 5";
  v1.setValue(5);

  QCOMPARE(result, true);
  disconnect(&amp;ac, &amp;AbstractCondition::conditionChanged, this, &amp;TestEngine::updateCondition);
  }
</code></pre>
<p dir="auto">TestEngine class is declared like this:</p>
<pre><code>class TestEngine : public QObject
{
  Q_OBJECT
public slots:
  void updateCondition(bool result) {
    qDebug() &lt;&lt; "TEST --- updateCondition to " &lt;&lt; (result ? "true" : "false");
    this-&gt;result = result;
    };

private slots:
  void testAndCondition();

  void init() { result = true; }

private:
  volatile bool result;
  };
</code></pre>
<p dir="auto">Debug logs look like:</p>
<pre><code>QDEBUG : TestEngine::testAndCondition() AbstractCondition::update() ...
QDEBUG : TestEngine::testAndCondition() GreaterCondition::eval() ...
QDEBUG : TestEngine::testAndCondition() compare signed integers (&gt;):  13 	value:  20
QDEBUG : TestEngine::testAndCondition() 	eval returned:  false
QDEBUG : TestEngine::testAndCondition() 	gonna fire condition changed event ...
QDEBUG : TestEngine::testAndCondition() AbstractCondition::update() ...
QDEBUG : TestEngine::testAndCondition() NotCondition::eval() ...
QDEBUG : TestEngine::testAndCondition() model type matches value type QVariant(int, 3) &lt;&gt; QVariant(int, 3)
QDEBUG : TestEngine::testAndCondition() 	eval returned:  false
QDEBUG : TestEngine::testAndCondition() 	gonna fire condition changed event ...
QDEBUG : TestEngine::testAndCondition() set v0 to 32
QDEBUG : TestEngine::testAndCondition() AbstractCondition::update() ...
QDEBUG : TestEngine::testAndCondition() GreaterCondition::eval() ...
QDEBUG : TestEngine::testAndCondition() compare signed integers (&gt;):  32 	value:  20
QDEBUG : TestEngine::testAndCondition() 	eval returned:  true
QDEBUG : TestEngine::testAndCondition() 	gonna fire condition changed event ...
QDEBUG : TestEngine::testAndCondition() AndCondition::eval() ... true &lt;&gt; false
QDEBUG : TestEngine::testAndCondition() set v1 to 5
QDEBUG : TestEngine::testAndCondition() AbstractCondition::update() ...
QDEBUG : TestEngine::testAndCondition() NotCondition::eval() ...
QDEBUG : TestEngine::testAndCondition() model type matches value type QVariant(int, 5) &lt;&gt; QVariant(int, 3)
QDEBUG : TestEngine::testAndCondition() 	eval returned:  true
QDEBUG : TestEngine::testAndCondition() 	gonna fire condition changed event ...
QDEBUG : TestEngine::testAndCondition() AndCondition::eval() ... true &lt;&gt; true
FAIL!  : TestEngine::testAndCondition() Compared values are not the same
</code></pre>
<p dir="auto">which means, that signal/slot connections work between ValueModel and conditionals, but not on a conditional, that depends on other conditionals?!?</p>
<p dir="auto">When I debug this test, value that should be published by emit signal is changed and code runs into emit call - but slot from TestEngine is not called.</p>
]]></description><link>https://forum.qt.io/topic/131757/problem-with-chained-signal-slot-connections</link><generator>RSS for Node</generator><lastBuildDate>Sun, 27 Sep 2026 05:07:51 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/131757.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 06 Nov 2021 17:58:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to problem with chained signal&#x2F;slot connections on Sun, 07 Nov 2021 03:37:44 GMT]]></title><description><![CDATA[<p dir="auto">Hi Christian,</p>
<p dir="auto">thank you very much for your attention and your question!</p>
<p dir="auto">I just wanted to explain, why result <em>should</em> change between second and third test and not between first and second test.<br />
<strong>... when I discovered my error!</strong></p>
<p dir="auto">I connected the wrong function to signals.<br />
Fixed that and now the tests pass :)</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://forum.qt.io/post/688826</link><guid isPermaLink="true">https://forum.qt.io/post/688826</guid><dc:creator><![CDATA[django.Reinhard]]></dc:creator><pubDate>Sun, 07 Nov 2021 03:37:44 GMT</pubDate></item><item><title><![CDATA[Reply to problem with chained signal&#x2F;slot connections on Sat, 06 Nov 2021 18:12:32 GMT]]></title><description><![CDATA[<p dir="auto">@django-Reinhard said in <a href="/post/688772">problem with chained signal/slot connections</a>:</p>
<blockquote>
<p dir="auto">QCOMPARE(result, false);</p>
<p dir="auto">qDebug() &lt;&lt; "set v1 to 5";<br />
v1.setValue(5);</p>
<p dir="auto">QCOMPARE(result, true);</p>
</blockquote>
<p dir="auto">How should <code>result</code> change between the first and the second test?</p>
]]></description><link>https://forum.qt.io/post/688774</link><guid isPermaLink="true">https://forum.qt.io/post/688774</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 06 Nov 2021 18:12:32 GMT</pubDate></item></channel></rss>