Adding slots to components dynamically in QML?
-
Description: I have many components on a parent component
root. Each of these components has a property calledparameterId. I would like to transmit from the backend different data stream to these components, depending on theparameterIdthat they have.So if
parameterId=3, then this component would receive the data stream from the parameter 3, and so on. These components would be created dynamically.Solution #1: Have every component connect to a single SIGNAL of type
object, as describbed here. Then every component would receive ALL data streams, and they could dynamically select which data to gather using theirparameterIdas the key to a javascript object in QML.I know how to do this, however, this seems it would be somewhat data inefficient, as there could be hundreds of components, receiving hundreds of data points many times per second.
Solution #2: Have the application create SLOTS for each component, for specific SIGNALS coming from the backend, based on their
parameterId, during startup.Solution #3: Have the root component connect to a single SLOT containing all the data streams (it receives a javascript object). Then it could call a Javascript function
updateValue(data)defined for each component, which updates their value.I want to implement Solution #2, but I cannot find anywhere saying how to do this inside QML, or in PySide2. Solution #3 is simpler, but it sounds like a "hack", and not the right way to do this (?)
-
I would use a model view approach. Then use the various "view" items from qml with c++ models.