senx
senx

Reputation: 650

Is there a QML type allowing to execute certain actions once some condition became true?

I need to execute some QML slot once certain condition became true.

I know there is a Binding type which can assign a property with some value once "when" condition became true. I need something similar but instead of setting the "value" to "property" I want to execute some arbitrary actions.

Thanks.

Upvotes: 0

Views: 186

Answers (3)

QtRoS
QtRoS

Reputation: 1177

It would be better to use Connections type:

Connections {
    target: conditionKeeper
    onConditionChanged: console.log("Processing...")
}

You could keep your logic in any QObject, even in C++. Once your condition becomes true, your code will be executed. It can be used out of the box without any dependencies.

Upvotes: 0

GrecKo
GrecKo

Reputation: 7160

There is a third party library that does that : benlau's QuickPromise

You could use it that way :

import QuickPromise 1.0
//...
Promise {
    resolveWhen: someExpression
    onFulfilled: arbitraryAction()
}

Upvotes: 3

peppe
peppe

Reputation: 22796

In other words, something like this?

QtObject {
    readonly property bool foobar: someExpression
    onFoobarChanged: {
         if (foobar) { ... }
    }
}

Upvotes: 4

Related Questions