• 2571阅读
  • 1回复

[提问]qt 中这样的语句实施什么意思? [复制链接]

上一主题 下一主题
离线ceiwei
 

只看楼主 倒序阅读 楼主  发表于: 2017-02-09
编程语言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();
        }
    }


离线cycloveu

只看该作者 1楼 发表于: 2017-02-10
QModelIndex():创建一个空的模型索引。作用是用来表明这个位置在模型中时合法的。
大道至简 悟在天成
快速回复
限100 字节
 
上一个 下一个