Using QAbstractItemModel in Models that haven't any list.
-
wrote on 12 Aug 2019, 15:28 last edited by
I want to show instant datas like speed,coordinate etc. on ui that I designed with Qml and I want to use model class derived from QAbstractItemModel.
But as I understand it,QAbstractItemModel designed for class that have table,list ... elements.
How can I use it for my design? -
Lifetime Qt Championwrote on 12 Aug 2019, 18:18 last edited by SGaist 8 Dec 2019, 21:44
Hi,
From the looks of it, it seems you rather want a QObject based class with various Q_PROPERTY for the values you want to show.
In any case, you should give more details about the data source and what you plan to show.
-
wrote on 12 Aug 2019, 18:32 last edited by
There are datas from ethernet include sensor data and gps information. I want to show all sensor datas on a chart and actual gps information on some labels and a map.
Do you have any suggestion for this scenario? -
So you have a list with two columns:
- Sensor name
- Sensor value
Correct ?
-
wrote on 12 Aug 2019, 19:41 last edited by
No. I have a one sensor. I want to show all output on a chart,actual(last) gps info(speed,course,time,hdop,pdop etc. on labels and actual(last) coordinate on map. Previous GPS datas will not be stored.
-
So you have some form of history you want to show ?
-
wrote on 12 Aug 2019, 20:18 last edited by
No,I haven't.
-
I fail to see the use of chart for that then. Do you have a drawing of the UI you want to make ?
-
wrote on 12 Aug 2019, 20:49 last edited by
Actually I wonder that can I use QAbstractItemModel for model that generate instant data. So view of that model will show only actual instant data.
Can I use QAbstractListModel for this purpose.That model have only one row and I will update that row periodically because I want to show only one data at the same time.
Is this usage correct? -
You can use it that way. It likely overkill but you can do it.
-
wrote on 12 Aug 2019, 21:15 last edited by
Or, should I use model derived from QObject and define variable that accessed from qml with Q_PROPERTY.
I have never use qml for commercial project before.Therefore I am invastigating proper way to use model/view pattern. -
Or, should I use model derived from QObject and define variable that accessed from qml with Q_PROPERTY.
I have never use qml for commercial project before.Therefore I am invastigating proper way to use model/view pattern.@overlord said in Using QAbstractItemModel in Models that haven't any list.:
I am invastigating proper way to use model/view pattern.
The model/view pattern in Qt is designed for cases where you have an arbitrary number of rows of data. Your sensors don't quite match this use-case. Therefore, the model/view pattern is not suitable for your sensors.
I suggest you choose the right tool for the job: Just use a data structure for your sensors, like @SGaist suggested.
If you want to investigate how to use the model/view pattern, try implementing a model with rows. For example, an address book.
7/12