Updating data model for QML while already displaying view
Hi,
I have a Qt project with QML ui interface designed to display information coming in about vehicle status. I use a carData object to store the information about the car. Right now, it is implemented like this:
Code:
int main(int argc, char *argv[])
{
MainWindow w;
carData *data = new carData();
w.rootContext()->setContextProperty("data", data);
w.show();
return a.exec();
}
However, information on car status is obviously constantly changing, so I want to update the carData object every second or so to reflect the most current data on the car. I can write an update method that will reset the contents of the carData object, but I am wondering how I will be able to do this once w.show() or a.exec() has been called. How can I continuosuly update the object being displayed while the display is already running? Would it work to do something along the lines of:
Code:
while(true) {
data->update();
w.show();
}
Re: Updating data model for QML while already displaying view
You need to properly implement your model based on QAbstractItemModel.