"Large" 使用 C++ Qt 和 Qt xlsx 模块读取 xlsx 文件

"Large" xlsx file reading using C++ Qt and Qt Xlsx Module

本文关键字:xlsx Qt 读取 文件 模块 Large 使用 C++      更新时间:2023-10-16

我正在使用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;
}

任何建议或想法都将不胜感激。

您必须NOT删除cell,因为它归QXlsx::Document所有。