请问我从txt文件中动态读取数据,在tablewidget中显示,如何对其中一列进行求和
这个是我读取文件的代码,提供思路或者代码都可,谢谢
mainbookprocesser::mainbookprocesser(QWidget *parent) :
QWidget(parent),
ui(new Ui::mainbookprocesser)
{
ui->setupUi(this);
ui->tableWidget->setColumnCount(7);
QStringList header;
header<<"书名"<<"作者"<<"出版日期"<<"总数量"<<"单价"<<"在馆数量"<<"类别";
ui->tableWidget->setHorizontalHeaderLabels(header);
QFile f("E:\\librarQTUI\\bookdata.txt");
f.open(QIODevice::ReadOnly|QIODevice::Text);
QTextStream output(&f);
QHash<QString,QString> varHash;
QString lineStr;
varHash.clear();
linelist.clear();
while(!output.atEnd())
{
lineStr=output.readLine();
linelist=lineStr.split("\t");
int rowCount=ui->tableWidget->rowCount();
ui->tableWidget->insertRow(rowCount);
for(int i=0;i<7;i++)
{
ui->tableWidget->setItem(rowCount,i,new QTableWidgetItem(linelist[i]));
}
}
f.close();