编程语言C++qt 修改标签model->removeRows(0,model->rowCount(QModelIndex()),QModelIndex());
(QModelIndex()这个是模型的最大索引号吗?我在帮助中只找到QModelIndex()这个类
rowCount(QModelIndex()这个是行数吗?
原始代码如下:
void MainWindow::openFile(
QString path)
{
if (!path.isEmpty())
{
QFile file(path);
if (file.open(QFile::ReadOnly|QFile::Text))
{
QTextStream stream(&file);
QString line;
model->removeRows(0,model->rowCount(QModelIndex()),QModelIndex());
int row = 0;
do
{
line = stream.readLine();
if (!line.isEmpty())
{
model->insertRows(row, 1, QModelIndex());
QStringList pieces=line.split(",",QString::SkipEmptyParts);
model->setData(model->index(row, 0, QModelIndex()),pieces.value(0));
model->setData(model->index(row, 1, QModelIndex()),pieces.value(1));
model->setData(model->index(row, 2, QModelIndex()),pieces.value(2));
model->setData(model->index(row, 3, QModelIndex()),pieces.value(3));
row++;
}
}while (!line.isEmpty());
file.close();
}
}