void Dialog::loadCSV(QString filename){ QFile file(filename); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; table.clear(); bool ok; qreal x,y; QTextStream in(&file); QString line = in.readLine(); // первая строка - заголовок. пропускаем while (!in.atEnd()) { line = in.readLine(); QStringList strList = line.split(QChar(',')); if (strList.size()<2) break; x = strList.at(0).toDouble(&ok); if (ok) y = strList.at(1).toDouble(&ok); if (!ok) break; table.append(QPointF(x,y)); } updateTableWidget();}void Dialog::updateTableWidget(){ ui->tableWidget->setColumnCount(2); if (table.size() == 0) { ui->tableWidget->setRowCount(1); ui->tableWidget->clear(); } else { ui->tableWidget->setRowCount(table.size()); for (int i=0; i<table.size(); ++i) { ui->tableWidget->setItem(i,0,new QTableWidgetItem(QString::number((double)table.at(i).x(),'f'))); ui->tableWidget->setItem(i,1,new QTableWidgetItem(QString::number((double)table.at(i).y(),'f'))); } }}
QVector<QPointF> table;void loadCSV(QString filename);void updateTableWidget();