PDA

View Full Version : Updating data model for QML while already displaying view



bluestreak
11th July 2012, 23:41
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:


int main(int argc, char *argv[])
{
QApplication a(argc, 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:


while(true) {
data->update();
w.show();
}

wysota
11th July 2012, 23:46
You need to properly implement your model based on QAbstractItemModel.