Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. problem with chained signal/slot connections
Qt 6.11 is out! See what's new in the release blog

problem with chained signal/slot connections

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 496 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    django.Reinhard
    wrote on last edited by
    #1

    Hi,

    I'm working on condition classes and this time I have trouble with 'AndCondition', which uses other conditionals.

    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.

    A stripped down testunit is available.

    Testcase looks like this:

    void TestEngine::testAndCondition() {
      ValueModel v0("left", 13);
      ValueModel v1("right", 3);
      GreaterCondition gc(&v0, 20);
      NotCondition     nc(&v1, 3);
      AndCondition     ac(gc, nc);
    
      connect(&ac, &AbstractCondition::conditionChanged, this, &TestEngine::updateCondition);
    
      QCOMPARE(result = ac.result(), false);
    
      qDebug() << "set v0 to 32";
      v0.setValue(32);
    
      QCOMPARE(result, false);
    
      qDebug() << "set v1 to 5";
      v1.setValue(5);
    
      QCOMPARE(result, true);
      disconnect(&ac, &AbstractCondition::conditionChanged, this, &TestEngine::updateCondition);
      }
    

    TestEngine class is declared like this:

    class TestEngine : public QObject
    {
      Q_OBJECT
    public slots:
      void updateCondition(bool result) {
        qDebug() << "TEST --- updateCondition to " << (result ? "true" : "false");
        this->result = result;
        };
    
    private slots:
      void testAndCondition();
    
      void init() { result = true; }
    
    private:
      volatile bool result;
      };
    

    Debug logs look like:

    QDEBUG : TestEngine::testAndCondition() AbstractCondition::update() ...
    QDEBUG : TestEngine::testAndCondition() GreaterCondition::eval() ...
    QDEBUG : TestEngine::testAndCondition() compare signed integers (>):  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) <> 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 (>):  32 	value:  20
    QDEBUG : TestEngine::testAndCondition() 	eval returned:  true
    QDEBUG : TestEngine::testAndCondition() 	gonna fire condition changed event ...
    QDEBUG : TestEngine::testAndCondition() AndCondition::eval() ... true <> 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) <> QVariant(int, 3)
    QDEBUG : TestEngine::testAndCondition() 	eval returned:  true
    QDEBUG : TestEngine::testAndCondition() 	gonna fire condition changed event ...
    QDEBUG : TestEngine::testAndCondition() AndCondition::eval() ... true <> true
    FAIL!  : TestEngine::testAndCondition() Compared values are not the same
    

    which means, that signal/slot connections work between ValueModel and conditionals, but not on a conditional, that depends on other conditionals?!?

    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.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @django-Reinhard said in problem with chained signal/slot connections:

      QCOMPARE(result, false);

      qDebug() << "set v1 to 5";
      v1.setValue(5);

      QCOMPARE(result, true);

      How should result change between the first and the second test?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • D Offline
        D Offline
        django.Reinhard
        wrote on last edited by
        #3

        Hi Christian,

        thank you very much for your attention and your question!

        I just wanted to explain, why result should change between second and third test and not between first and second test.
        ... when I discovered my error!

        I connected the wrong function to signals.
        Fixed that and now the tests pass :)

        Thanks!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved