码迷,mamicode.com
首页 > 其他好文 > 详细

Qt tableview加载数据

时间:2019-10-25 20:02:33      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:int   com   student   import   page   etc   for   dex   height   

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);
}

技术图片

Qt tableview加载数据

标签:int   com   student   import   page   etc   for   dex   height   

原文地址:https://www.cnblogs.com/herd/p/11739850.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!