0
我正在編寫一個程序,該程序讀取製表符分隔雙精度的文本文件,並總結每列,從而有效地計算每列的積分。Qt讀取製表符分隔文本文件的特定列
我希望能夠做的是選擇一個特定的列來總結而不是總和所有的列。
我已經有工作了所有列的積分代碼:
void MainWindow::on_pushButton_clicked()
{
data::SingleLineData.resize(512);
QString test;
QString inputfile = QFileDialog::getOpenFileName(
this,
tr("Open File"),
"/Users",
"All files (*.*)"
);
if(inputfile != ""){
QFile file(inputfile);
if(!file.open(QFile::ReadOnly)){
}
QTextStream in(&file);
double buffer;
while(!file.atEnd()){
in.readLine();
for(int i=0; i<512; i++){
in >> buffer;
data::SingleLineData[i]+=buffer;
}
}
}
qDebug() << data::SingleLineData;
// ************* file output **************************************************
QString filename = QFileDialog::getSaveFileName(
this,
tr("Save File"),
"/Users",
"Text files (*.txt)"
);
QFile fileout(filename);
if (fileout.open(QFile::ReadWrite | QFile::Truncate)){
QTextStream out(&fileout);
for (QVector<double>::iterator iter = data::SingleLineData.begin(); iter != data::SingleLineData.end(); iter++){
out << *iter <<", ";
}
fileout.close();
}
}
這裏是我利用整數輸入到旋轉框中選擇了某個列嘗試:
void MainWindow::on_pushButton_2_clicked()
{
QString inputfile = QFileDialog::getOpenFileName(
this,
tr("Open File"),
"/Users",
"All files (*.*)"
);
QVector<double> SingleChannel;
if (inputfile != ""){
QFile file(inputfile);
if (!file.open(QIODevice::ReadOnly)){
}
QTextStream in(&file);
SingleChannel.resize(1);
double buffer;
int channelnumber = ui->spinBox->value();
while(!file.atEnd()){
in.readLine();
for (int i = 0; i < 512; i++){
in >> buffer;
if (i == channelnumber){
SingleChannel.push_back(buffer);
}
data::SingleLineData[i]+=buffer;
}
}
}
qDebug() << SingleChannel;
}
我碰到下面的錯誤,但:
ASSERT failure in QVector<T>::operator[]: "index out of range", file /Users/mduncan/Qt/5.3/clang_64/lib/QtCore.framework/Headers/qvector.h, line 385
The program has unexpectedly finished.
人有什麼想法?
謝謝:)
非常感謝 – 2015-03-03 02:34:08