neutri
neutri

Reputation: 57

Dynamically update QML GUI values

I have bunch of data that has to be displayed continuously on the GUI. I can actually achieve it by setting timer and assigning the new values to the displayed values but I do not want to do in that way. Is there any solution or practical way to do that?

Upvotes: 0

Views: 728

Answers (3)

neutri
neutri

Reputation: 57

First, I defined the property and added the notifier called payloadChanged to the signals of my class.


    Q_PROPERTY(QList<qreal> PayloadList READ getPayloadList NOTIFY payloadChanged)

Secondly,

    qmlRegisterType<<YOUR_CLASS_NAME>>("sample1.sample2", 1, 0, "<QML_ITEM_NAME>");

Finally

QML_ITEM_NAME{
    console.log("PROPERTY")
}


When I applied these steps my data is automatically updated without any timer stuff.

Upvotes: 0

Marco Medri
Marco Medri

Reputation: 304

I think you have two options to achieve that:

  1. All your data have a Q_PROPERTY. That means create a get function and a signal
  2. If you want to show them under a list or a treeview, I suggest you gather all the data up, under a QAbstractListModel. https://doc.qt.io/qt-5/qabstractlistmodel.html

Then implementing the function data, index, ecc., you will have everything already done for the UI

Upvotes: 2

Have you tried using Q_Property? Notify Signal may work for your situation. You can find the documentation from here.

Upvotes: 1

Related Questions