qtablewidget 表格赋值,通过json的值直接赋值。
void UiHelper::setData(QTableWidget *tableWidget, const QJsonArray &data)
{
while(tableWidget->rowCount()>0)
{
tableWidget->removeRow(0);
}
QString objname = tableWidget->objectName();
QStringList ls = datautil::getConfigData(objname+"/title");
int row = 0;
foreach(QJsonValue v,data)
{
tableWidget->insertRow(row);
QJsonObject o = v.toObject();
int col = 0;
foreach (QString key, ls) {
tableWidget->setItem(row,col,new QTableWidgetItem(o[key].toString()));
col++;
}
row++;
}
}