It looks like I've come full circle. 
I originally started this project a long time ago but then with my daughters birth had put things on hold. I'm now managing to scrape some time here and there so thought I would start it up again.
wysota, I've now created a QAbstractListModel derived object which stores my data in an internal QVector. This is working beautifully in the QML side and I have a TableView that shows all entries and updates correctly when the internal data updates.
{
private:
QVector<Data> m_Data;
};
class DataEngine : public QAbstractListModel
{
private:
QVector<Data> m_Data;
};
To copy to clipboard, switch view to plain text mode
This leads me onto the second issue which was what I originally faced so long ago - Data is added to my 'data engine' dynamically at runtime, I dont know prior to runtime what data will be available. I need to be able to bind a QML object's value to a data entry and have the QML object also update when the data changes.
MyQmlObject
{
value: runtime.abc // <-- abc is a dynamic, we dont know until runtime that there is a property called abc
}
MyQmlObject
{
value: runtime.abc // <-- abc is a dynamic, we dont know until runtime that there is a property called abc
}
To copy to clipboard, switch view to plain text mode
As far as I'm aware there is no mechanism exposed in Qt to allow for dynamic properties (other than using QQmlPropertyMap, QQmlListProperty etc)? If this is correct do I go about binding a UI element's value to a data entry? I guess I could always use a Q_INVOKABLE member to return the data however, how would I then get the QML object to upadte when the value has changed?
I'm currently thinking I'll have to use a QQmlListProperty as my internal data storage for my QAbstractListModel derived object. The problem is this leads back to the original issue - I now have to either:
- Make sure a data entry can only ever be modified through the QAbstractListModel derived object (to keep the update notifications of QAbstractListModel and the QQmlPropertyList in sync)
OR
- Find a way to detect a change in a data entry and inform the QAbstractListModel that it also needs to update.
I hope that makes sense? Any thoughts/suggestions?
Bookmarks