QTableView加载数据

void VCAdmin::searchAllUser()
{
    strID_Index = "";
    if (NULL == vcManageDatabaseObj)
    {
        vc_admin_ui.label_msg->setText(QString::fromLocal8Bit("请连接数据库!"));
        return;
    }
    QSqlQuery query_sql = vcManageDatabaseObj->searchAllUser();

    admin_model->clear();
    int count_sr1 = 0;
    while (query_sql.next())
    {

        QString strID = query_sql.value(0).toString();
        QString strUSerName = query_sql.value(1).toString();
        QString strUserPWd = query_sql.value(2).toString();

        QString strRealName = query_sql.value(3).toString();
        QString strMobile = query_sql.value(4).toString();
        QString strCreator = query_sql.value(5).toString();
        QString strCreateDate = query_sql.value(6).toString();

        admin_model->setItem(count_sr1, 0, new QStandardItem(strID));
        admin_model->setItem(count_sr1, 1, new QStandardItem(strUSerName));
        admin_model->setItem(count_sr1, 2, new QStandardItem(strUserPWd));
        admin_model->setItem(count_sr1, 3, new QStandardItem(strRealName));

        admin_model->setItem(count_sr1, 4, new QStandardItem(strMobile));
        admin_model->setItem(count_sr1, 5, new QStandardItem(strCreator));
        admin_model->setItem(count_sr1, 6, new QStandardItem(strCreateDate));

        count_sr1++;
    }

    //设置数据
    setTableData();
}

 

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