0
votes

I want to write some QML to edit a CSV file, presenting a grid-like array of textboxes to allow user input/output. I plan to write a C++ subclass of QAbstractTableModel to represent the file, I can foresee no problems with doing so. My subclass will index the fields using rows and columns. I won't use "roles as columns" as the number of columns will change at runtime based on the file the user chooses to load.

Is there a QML control that will render my QAbstractTableModel? The answers to similar problems online suggest using roles for columns, but I'd rather use the column numbering offered by QModelIndex.

Here's an insanely simple QAbstractTableModel for starters - a two by two grid of "Blob"s. I'd like to render this in QML

class CsvGridModel: public QAbstractTableModel
{
public:
    CsvGridModel();

    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override {return 2;}
    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override {return 2;}
    virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override {return "Blob";}
};

I'm using Qt 5.11.3

1

1 Answers

1
votes

TableView is a view for, well, table models.