Which model to choose?
I've read through the model/view tutorial and want to implement this in my program to optimize the GUI time consumed. In a (QTableWidget) I display a Id, then a progressbar containing a RF receiving strength indication and in the third column a name can be given.
What model should I chose? QStandardItemModel? A QAbstractItemModel?? I'm a bit lost in the model the use? What is the benefit or downside off either?
Thx for any advise or link to where to read the stuff.
QAbstractItemModel as the name suggests is an Interface, you can't use it directly, you'd have to derive from it and implement certain functions yourself (like QAbstractItemModel::data). QStandardItemModel is a generic implementation that you can use directly, with an interface similar to QTableWidget (you add and remove items and they get displayed).
If this interface is good for your use case, QStandardItemModel will save you work. If you feel you'd have to take detours to get your data through the QStandardItemModel-interface (like converting data a lot) you're probably better off deriving from QAbstractItemModel.
Well its all based on your requirement, From the book "Advance Qt Programming":http://www.cuteqt.com/blog/wp-content/uploads/2009/06/Advanced_Qt_Programming.pdf in the first chapter of model/view table models it is given that :-
bq. In addition to considering the two kinds of model, there are three types of model
we can use. One type is any of the predefined models that Qt provides, for
example, the QStringListModel, the QDirModel, and its successor the QFileSystem-
Model—these can be used directly and require the least amount of work to use.
bq. Another type is the QStandardItemModel; this is a generic model that can be used
as a list, table, or tree model, and that provides an item-based API rather like
the APIs offered by the convenience widgets (such as QTableWidget). Using a
QStandardItemModel is ideal for those cases where we have data that fits neatly
into the idiom of a list, table, or tree of items, and can be used as is or usually
with very little adaptation.
bq. And the last type is our own custom models derived
from QAbstractItemModel (or from QAbstractListModel or QAbstractTable-
Model). These are ideal when we want to achieve the best possible performance,
or where our model doesn’t fit neatly into an item-based idiom.
So pick one that you feel more handy/comfortable.
Hi. I used in an application QAbstractItemModel. It caused me some problems specially when deleting and inserting rows and columns. So I switch to QStandardItemModel. It's more generic and I found it easiest. Well, you can download the application in my web-page under the source codes link : AHP method. The model implementation is in the file matrixmodel.h !
I hope that it will help you :)
Hi, Thx for the replies!
Will try to implement the QStandardItemModel at first. It seems the most easy way to go.