I have a C++ implemented Quick Item and it offeres multiple properties and Q_INVOKABLE methods with return values. Most of these methods depend on these properties.
Can I define a notify signal for methods? Or when binding to it, can I add additional dependencies so the method is evaluated again?
In this example I want all text items to be updated whenever theItem.something
changes.
SimpleCppItem {
id: theItem
something: theSpinBox.value
}
RowLayout {
SpinBox { id: theSpinBox; }
Repeater {
model: 10
Text { text: theItem.computeWithSomething(index) }
}
}
The implementation of the SimpleCppItem
looks like this:
class SimpleCppItem : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(int something READ something WRITE setSomething NOTIFY somethingChanged)
public:
explicit SimpleCppItem(QQuickItem *parent = Q_NULLPTR) :
QQuickItem(parent),
m_something(0)
{ }
Q_INVOKABLE int computeWithSomething(int param)
{ return m_something + param; } //The result depends on something and param
int something() const { return m_something; }
void setSomething(int something)
{
if(m_something != something)
Q_EMIT somethingChanged(m_something = something);
}
Q_SIGNALS:
void somethingChanged(int something);
private:
int m_something;
};