我正在使用 Qt 框架在 C++ 中开发应用程序,但我需要读取 .xslx 文件以将其导入 sqlite 数据库。我正在使用 Qt Xlsx 模块,但我发现了一些困难,因为我的程序在执行期间的某个随机点崩溃了。该文件大约有 1500 行和 10 列。我能够读取 700 到 1000 行,但随后它崩溃了。我认为这是一个内存问题,但我无法使用 Valgrind,因为我在 Mac OS X 系统上。 我的代码的相关部分如下。
void Controller::ImportDatabase(const QString &filepath)
{
QStringList* person_fields = new QStringList;
QXlsx::Document *xlsx_database = new QXlsx::Document(filepath);
int number_of_row = xlsx_database->dimension().lastRow();
int number_of_column = xlsx_database->dimension().lastColumn();
for (int row = 2; row <= number_of_row; ++row) {
++count;
qDebug() << "count: " << count;
for(int column = 0; column < number_of_column ; ++column) {
if ((QXlsx::Cell *cell = xlsx_database->cellAt(row, column))) {
person_fields->append(cell->value().toString());
delete cell;
}
}
qDebug() << "NOME: " << person_fields->at(0);
//Create a new Person and pass its pointer around: all commented anyway
person_fields->clear();
delete cell;
}
delete person_fields;
delete xlsx_database;
}
如有任何建议或想法,我们将不胜感激。
最佳答案
你绝对不能不删除cell
,因为它属于QXlsx::Document。
关于c++ - "Large"使用C++ Qt和Qt Xlsx模块读取xlsx文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34514149/