Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

large memery usage when export data from MYSQL to excel #304

Open
wuyuewei opened this issue Sep 5, 2023 · 0 comments
Open

large memery usage when export data from MYSQL to excel #304

wuyuewei opened this issue Sep 5, 2023 · 0 comments

Comments

@wuyuewei
Copy link

wuyuewei commented Sep 5, 2023

The mysql database data size is 40909 rows and 50 colums, when use the code to export these data as blew the computer memery will be reached to 800Mb. the real excel file size only 7Mb. could anyone told me how to decrease the memery usage?
`
QXlsx::Document xlsx;
QXlsx::Format format;
QModelIndex indexItem;
QVariant data ;

    if(exportFileName.isEmpty())
        return;
    QFile file(exportFileName);;
    if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
    {
        MsgBox *msgBox = new MsgBox(Msg_Warning,exportFileName + "\n" + tr("The file is opend,please close file!"));
        msgBox->exec();
        delete msgBox;
        return;
    }
    else
    {  
        int rowCount = modelCrm->rowCount();
        int colCount = modelCrm->columnCount();
        ui->progressBar->setMaximum(rowCount);

        for (int i = 0; i < rowCount;i++)
        {
            QCoreApplication::processEvents();
            for(int j = 0; j < colCount; j++)
            {
                indexItem = modelCrm->index(i,j,QModelIndex());//rowNum,columnNum为行列号
                data = indexItem.data();
                    xlsx.write(i+3,j+1, data.toString());
            }
        }
    }
    QFuture<void> future = QtConcurrent::run([&]() {
        qDebug() << __FUNCTION__ << QThread::currentThreadId() << QThread::currentThread();
        xlsx.saveAs(exportFileName);
    });
    ui->progressBar->setRange(0, 0);
    // Set the progress bar to an indeterminate state
    while (!future.isFinished()) {
        QApplication::processEvents(QEventLoop::AllEvents, 10);
    } `
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant