根据提供的代码,有几个问题需要注意:
iniDataRowCount
和fixedColumnCount
变量未在代码中定义,需要确认它们的值。在
initData()
函数中,colNoName
和colNoAverage
变量未在代码中定义,需要确认它们的值。在
sureyData()
函数中,统计分数段的逻辑出现了错误。你应该在外层循环迭代行而不是列。此外,在更新QTreeWidgetItem
的文本时,应使用正确的索引值。以下是修正后的代码片段:
void MainWindow::sureyData() // 统计分数段
{
int cnt50 = 0, cnt60 = 0, cnt70 = 0, cnt80 = 0, cnt90 = 0;
for (int j = 0; j < theModel->rowCount(); j++) {
for (int i = colNoMath; i < colNoAverage; i++) {
QStandardItem *item = theModel->item(j, i);
if (item->text().toInt() < 60) {
cnt50++;
}
else if (item->text().toInt() < 70) {
cnt60++;
}
else if (item->text().toInt() < 80) {
cnt70++;
}
else if (item->text().toInt() < 90) {
cnt80++;
}
else if (item->text().toInt() <= 100) {
cnt90++;
}
}
QTreeWidgetItem *titem = ui->treeWidget->topLevelItem(0);
titem->setText(j + colNoMath, QString::number(cnt50));
titem = ui->treeWidget->topLevelItem(1);
titem->setText(j + colNoMath, QString::number(cnt60));
titem = ui->treeWidget->topLevelItem(2);
titem->setText(j + colNoMath, QString::number(cnt70));
titem = ui->treeWidget->topLevelItem(3);
titem->setText(j + colNoMath, QString::number(cnt80));
titem = ui->treeWidget->topLevelItem(4);
titem->setText(j + colNoMath, QString::number(cnt90));
cnt50 = 0;
cnt60 = 0;
cnt70 = 0;
cnt80 = 0;
cnt90 = 0;
}
}
请根据以上修正尝试运行代码并查看是否解决了问题。
内容由零声教学AI助手提供,问题来源于学员提问