Important: Please read the Qt Code of Conduct -

Help me choose data model and view layout

  • I am completely new in QML and Qt Quick.
    I've read some manuals, saw some examples and did my own C++ class with set of parameters(properties) and signals/slots for each parameter change notifications(both from model to view and view to model changes).

    But later i found that QML have data models with delegates and now i am confused. May be i should use them?
    Seems to be my data is not so well suited for using data models, but may be i am not clearly understood them yet..

    My data is a set of device(internal combustion engine control unit) parameters.
    Parameters are: number parameter, array(2D or 3D table), enumeration parameter(choose from list), bitfield parameter(group of checkboxes), string parameter.
    This parameters are grouped by categories and shown in different tabs.

    As i can see, only arrays are well suited for displaying in the grid or list. I have no idea about how to represent rest of parameters.

    It is a good decision to make signal/slot for each parameter(like i did now)?
    Please help me to solve a problem in true Qt Quick way.

    Let me know if my post is incomlete and you need more information about data or whatever..

  • Moderators

    @sigmaN For arrays/list like structures its better to use ListView or GridView as a view. For a model you can use QAbstractItemModel and your already existing C++ logic in it. To make it work with QML have a look at C++ Models with Qt Quick Views.

    enumeration parameter(choose from list)

    For this I think its better to write a separate class with Q_INVOKABLE methods or public slots so as to access them from QML. You will need to embed it into QML. This explains how to do it.

    Now for a view you can use a ComboBox. It accepts a model too. Here you can use a QStringListModel to contain the data. This model can be returned from one of the Q_INVOKABLE methods said above.

    bitfield parameter(group of checkboxes),

    A Q_INVOKABLE method in same class which can return data depending upon say checkbox's for eg. name.

    It is a good decision to make signal/slot for each parameter(like i did now)?

    Normally you would use that in case you want to notify other objects or perform some tasks in non blocking way upon some change. So it depends completely on the requirement.

  • Thank you very much! Now it is much more clear for me.

Log in to reply