How to make qml aware of changes happened in C++ side?
Imagine you have a Qvector of Qstring type and you put some names there something like :
Qvector<QString> names; name.append("Sara"); ... name.append("Caroline"); name.append("Isabella");
In qml you implement a repeater to show these names inside of some rectangles.What if you change one name of this vector from c++ side?How you can force repeater to repeat again and update the qml side to show new names?
How many ways are exist for that and which one has better performance?
I guess you are after a property binding.
Thus you should define a custom type with a
QStringListproperty. Make sure that the property has a
NOTIFYsignal and trigger this signal whenever the property changes.
Q_PROPERTY( QStringList myList READ getMyList WRITE setMyList NOTIFY myListChanged )
Then trigger the
myListChangedsignal in the
Dear @raven-worx ,
That's true one solution is using model of repeater like QStringList, QAbstractItemModel,etc but is there any other solution for that something that cause repaint in qml item therefor repeater force to repeat again and finally shows updated data on the screen?
why would it just need to be repainted?
If the data has changed you should notify it as i said. Or in case of a QAbstractItemModel emit the dataChanged() signal
Thanks for your solution it seems that there is no need to repaint,Thank you.