problem with chained signal/slot connections
-
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 samewhich 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.
-
@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
resultchange between the first and the second test? -
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!