0
QVector <QString> frequency;
QVector <QString> gain;
QString ref_data;
QStringList rowOfData;
QStringList rowData;

if (ReferenceData.open(QIODevice::ReadOnly | QIODevice::Text)) {
    ref_data = ReferenceData.readAll();
    rowOfData = ref_data.split("\n");
    ReferenceData.close();
}

for (int x = 9; x < rowOfData.size(); x++) {
    rowData = rowOfData.at(x).split(",");
    frequency.push_back(rowData[0]);
    gain.push_back(rowData[1]);
}

我从一个文件中读取了所有数据。当我使用push_back时,我得到一个错误QList<T>::operator[] "index out of range"。我也用过frequency.push_back(rowData.at(0));,然后QList<T>::at "index out of range"报错!

如何解决这个问题?

4

1 回答 1

2

后面的循环应该处理坏行,例如像这样,只是用调试打印跳过它们:

for (int x = 9; x < rowOfData.size(); x++) {
    rowData = rowOfData.at(x).split(",");
    if (rowData.size() >= 2) {
        frequency.push_back(rowData[0]);
        gain.push_back(rowData[1]);
    }
    else qDebug() << "Skipping bad row" << x << rowOfData.at(x);
}
于 2013-04-20T20:38:34.380 回答