Quantcast
Viewing all articles
Browse latest Browse all 4972

Expose C++ QVariantList to QML with setContextProperty : view in QML in not updated when I change data

Hi, I am making a data exchange between C++ (JSON RPC server with some additional logic) and QML. For a list of complex objects, I store them in a C++ QMap, and construct a QVariantList from that. This list is used as a model for a grid view in QML, with bindings to the item properties. It basically works but the visual updating only happens in some cases : The QVariant list consists of objects with public properties such as  Q_PROPERTY(long weight READ getweight  WRITE setweight NOTIFY weightChanged) The list is exposed to QML after every change, using : GUIRootContext->setContextProperty("GateList", QVariant::fromValue(myGateList)); Now when I change the weight poperty of an item in the list, and call this setContextProperty afterwards, the value is not updated in the grid. So in that case updating/binding does not work. When I add an additional items to the list, the new object is added in the grid , and the previous updates are now shown too (for the other objects where i had changed properties). So in this case updating/binding it triggered. It seems setContextProperty does not trigger binding evaluation every time, it depends on the detected changes, and changes inside objects are not considered. Probably this is normal behaviour, but what is the right way to do it ? Is there a good way to sync a item updates (for items in a list or map) from C++ to QML ? tnx serdef

Viewing all articles
Browse latest Browse all 4972

Trending Articles