Qt tableview加载数据

Qt tableview加载数据

//把数据加载到tableView
void ImportData::loadDataInTableView()
{
    if (student_vec.size()>0)
    {
        if (pageNum>student_vec.size())
        {
            pageNum = student_vec.size();
        }
        else
        {
            pageNum = 30;
        }

        //qDebug()<< "student_vec size:" << student_vec.size() << "  page num:" << pageNum;
        student_model->clear();
        setTableHeader();
        int k = 0;
        for (int k1 = (indexPage - 1)*pageNum; k1<indexPage*pageNum; k1++)
        {
            if (k1<student_vec.size())
            {
                Student studentIndex = student_vec.at(k1);
                student_model->setItem(k, 0, new QStandardItem(QString::number(studentIndex.getID())));
                student_model->setItem(k, 1, new QStandardItem(studentIndex.getName()));
                if (studentIndex.getSex() == "1")
                {
                    student_model->setItem(k, 2, new QStandardItem(QString::fromLocal8Bit("")));
                }
                else
                {
                    student_model->setItem(k, 2, new QStandardItem(QString::fromLocal8Bit("")));
                }

                student_model->setItem(k, 3, new QStandardItem(studentIndex.getBirthday()));
                student_model->setItem(k, 4, new QStandardItem(QString::number(studentIndex.getWeight())));
                student_model->setItem(k, 5, new QStandardItem(QString::number(studentIndex.getHeight())));
                student_model->setItem(k, 6, new QStandardItem(studentIndex.getPhoneNum()));

                student_model->setItem(k, 7, new QStandardItem(studentIndex.getAddress()));
                student_model->setItem(k, 8, new QStandardItem(studentIndex.getSchoolName()));
                student_model->setItem(k, 9, new QStandardItem(studentIndex.getSchoolType()));
                student_model->setItem(k, 10, new QStandardItem(QString::number(studentIndex.getGradeNum())));

                student_model->setItem(k, 11, new QStandardItem(QString::number(studentIndex.getClassNum())));
                student_model->setItem(k, 12, new QStandardItem(studentIndex.getSID()));
                student_model->setItem(k, 13, new QStandardItem(studentIndex.getIDCardNum()));

                k++;
            }
        }
    }
    import_data_ui.tableView_list->setModel(student_model);
}

posted @ 2019-10-25 19:14  西北逍遥  阅读(5134)  评论(0编辑  收藏  举报