Qt tableview加载数据
//把数据加载到tableView
void ImportData::loadDataInTableView()
{
if (student_vec.size()>)
{
if (pageNum>student_vec.size())
{
pageNum = student_vec.size();
}
else
{
pageNum = ;
} //qDebug()<< "student_vec size:" << student_vec.size() << " page num:" << pageNum;
student_model->clear();
setTableHeader();
int k = ;
for (int k1 = (indexPage - )*pageNum; k1<indexPage*pageNum; k1++)
{
if (k1<student_vec.size())
{
Student studentIndex = student_vec.at(k1);
student_model->setItem(k, , new QStandardItem(QString::number(studentIndex.getID())));
student_model->setItem(k, , new QStandardItem(studentIndex.getName()));
if (studentIndex.getSex() == "")
{
student_model->setItem(k, , new QStandardItem(QString::fromLocal8Bit("女")));
}
else
{
student_model->setItem(k, , new QStandardItem(QString::fromLocal8Bit("男")));
} student_model->setItem(k, , new QStandardItem(studentIndex.getBirthday()));
student_model->setItem(k, , new QStandardItem(QString::number(studentIndex.getWeight())));
student_model->setItem(k, , new QStandardItem(QString::number(studentIndex.getHeight())));
student_model->setItem(k, , new QStandardItem(studentIndex.getPhoneNum())); student_model->setItem(k, , new QStandardItem(studentIndex.getAddress()));
student_model->setItem(k, , new QStandardItem(studentIndex.getSchoolName()));
student_model->setItem(k, , new QStandardItem(studentIndex.getSchoolType()));
student_model->setItem(k, , new QStandardItem(QString::number(studentIndex.getGradeNum()))); student_model->setItem(k, , new QStandardItem(QString::number(studentIndex.getClassNum())));
student_model->setItem(k, , new QStandardItem(studentIndex.getSID()));
student_model->setItem(k, , new QStandardItem(studentIndex.getIDCardNum())); k++;
}
}
}
import_data_ui.tableView_list->setModel(student_model);
}