I need some general advice to point me in the correct direction of solving this problem: I have a .txt file with table data like the following:
Time Pin 11:00 EIO4 12:55 EIO6 16:40 EIO4 20:10 EIO3 etc......
I need to be able to parse this .txt file. Then I need to display this table in Qt (perhaps in a
I have looked into using QTableView, and it appears I pass a
QAbstractItemModel* to the
QTableView::setModel(QAbstractItemModel* model), after which my QTableView will display whatever data is in the QAbstractItemModel (right?).
If that last paragraph was logical, then my next question is how do I construct a
QAbstractItemModel using my .txt file? I don't see any functions in the documentation that do this? (Note: someone suggested creating a QStandardItemModel)
(Note, this paragraph is no longer relevant)
QModelIndex createIndex(int row, int collumn, void* ptr) appears to have something to do with this, maybe? Maybe this creates a
QModelIndex that can be passed to the
QAbstractItemModel::insertRow(QModelIndex)? However I still don't know how to make these
QModelIndex objects have anything to do with my .txt data.
QStandardItemModel documentation says
When you want a list or tree, you typically create an empty
appendRow()to add items to the model, and
item()to access an item. If your model represents a table, you typically pass the dimensions of the table to the
QStandardItemModelconstructor and use
setItem()to position items into the table. You can also use
setColumnCount()to alter the dimensions of the model. To insert items, use
insertColumn(), and to remove items, use
These functions that "add rows" take
QList<QStandardItem*>'s as arguments, so I need to create QLists that each contain pointers QStandardItems that contain each cell's data?
So I will use
void QStandardItemModel::insertRow(int row, const QList<QStandardItem *> & items)
Along with an argument
QList<QStandardItem*> generated by repeated calls of "
QStandardItem* pointers to an empty
I will make
QStandardItem's using the constructor
QStandardItem::QStandardItem(const QString & text)
where I get my
QString text by parsing a QFile into QStrings.
Everything looking good?
Or maybe I should skip creating QLists and go directly from generating
QStandardItem's to passing them into the
void QStandardItemModel::setItem(int row, int column, QStandardItem * item)
Edit: I ended up skipping creating QLists with the following process: QFile file -> QString line -> QStringList peices -> QStandardItem -> QStandardItemModel -> QTableView
Thanks to all who contributed