The beginInsertRows() and endInsertRows() functions are for use inside the model implementation around the logic that populates the model's internal data structures.
The insertRows() function is a public API for manipulating the model content from outside the model.
Are you implementing a table model of your own, or are you simply populating a QStandardItemModel (or similar existing model)?
if you are doing the latter then this works:
#include <QApplication>
#include <QStandardItemModel>
#include <QTableView>
#include <QFile>
#include <QTextStream>
int main(int argc, char **argv)
{
model.setColumnCount(10);
return 1;
while (!in.atEnd()) {
int row = model.rowCount();
model.insertRow(row);
double value;
for (int col = 0; col < 10; ++col) {
in >> value;
model.setData(model.index(row, col), value);
}
in.skipWhiteSpace();
}
view.setModel(&model);
view.show();
return app.exec();
}
#include <QApplication>
#include <QStandardItemModel>
#include <QTableView>
#include <QFile>
#include <QTextStream>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QStandardItemModel model;
model.setColumnCount(10);
QFile file("test.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return 1;
QTextStream in(&file);
while (!in.atEnd()) {
int row = model.rowCount();
model.insertRow(row);
double value;
for (int col = 0; col < 10; ++col) {
in >> value;
model.setData(model.index(row, col), value);
}
in.skipWhiteSpace();
}
QTableView view;
view.setModel(&model);
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Test.txt:
1.23 1.12 1.19 2.12 2.22 2.01 3.1 3.2 3.01 3.1
1.70 1.11 1.88 2.01 2.10 2.92 3.01 3.12 3.21 3.2
1.70 1.11 1.88 2.01 2.10 2.92 3.01 3.12 3.21 3.2
1.12 1.30 1.91 2.11 2.31 2.11 3.22 3.11 3.45 3.5
1.34 1.12 1.65 2.01 2.09 2.09 3.11 3.44 3.55 3.1
1.90 1.13 1.34 2.07 2.08 2.06 3.01 3.02 3.02 3.4
1.12 1.34 1.89 2.03 2.07 2.03 3.32 3.11 3.21 3.1
1.12 1.34 1.89 2.03 2.07 2.03 3.32 3.11 3.21 3.1
1.12 1.34 1.89 2.03 2.07 2.03 3.32 3.11 3.21 3.1
1.23 1.12 1.19 2.12 2.22 2.01 3.1 3.2 3.01 3.1
1.70 1.11 1.88 2.01 2.10 2.92 3.01 3.12 3.21 3.2
1.70 1.11 1.88 2.01 2.10 2.92 3.01 3.12 3.21 3.2
1.12 1.30 1.91 2.11 2.31 2.11 3.22 3.11 3.45 3.5
1.34 1.12 1.65 2.01 2.09 2.09 3.11 3.44 3.55 3.1
1.90 1.13 1.34 2.07 2.08 2.06 3.01 3.02 3.02 3.4
1.12 1.34 1.89 2.03 2.07 2.03 3.32 3.11 3.21 3.1
1.12 1.34 1.89 2.03 2.07 2.03 3.32 3.11 3.21 3.1
1.12 1.34 1.89 2.03 2.07 2.03 3.32 3.11 3.21 3.1
To copy to clipboard, switch view to plain text mode
Bookmarks