0

QuaZip を使用して .zip ファイルを抽出し、その抽出の進行状況を QProgressDialog に表示するにはどうすればよいですか?

この質問1 (およびこの質問2 )の例を試してみましたが、成功しませんでした。.zip ファイル (.gz ファイルではない) を解凍する必要があり、そのコードには進行状況の割合が表示されますが、ファイルは解凍されないためです。それでも、QProgressDialog でその % を表示する方法がわかりません。

以下を使用して .zip ファイルを抽出できました。

JlCompress::extractDir("C:/test/test.zip", "C:/test/");

ただし、QProgressDialog で抽出の進行状況をリアルタイムで表示する必要があるため、それは私の目標には十分ではありません...

これは私のコードです:

QString fileName = "C:/test/firefox-29.0.1.gz"; //I need to unzip .zip files
qDebug() << "Opened";
progressUnzip->setWindowTitle(tr("Unzip Manager"));
progressUnzip->setLabelText(tr("Unzipping %1. \nThis can take a long time to complete").arg(fileName));
progressUnzip->setAttribute(Qt::WA_DeleteOnClose);

QFile file(fileName);
file.open(QFile::ReadOnly);
QuaGzipFile gzip;
gzip.open(file.handle(), QuaGzipFile::ReadOnly);

progressUnzip->show();

while(true) {
    QByteArray buf = gzip.read(1000);
    //process buf
    if (buf.isEmpty()) { break; }
    QFile temp_file_object;
    temp_file_object.open(file.handle(), QFile::ReadOnly);
    double progress = 100.0 * temp_file_object.pos() / file.size();
    updateUnzipProgress(temp_file_object.pos(), file.size());
    qDebug() << qRound(progress) << "%";
}
unzipFinished();

qDebug() << "Finish";

どこ:

void MainWindow::updateUnzipProgress(qint64 bytesRead, qint64 totalBytes)
{
    qDebug() << bytesRead << "/" << totalBytes;
    qint64 th = 1;
    if (totalBytes >= 100000000)
    {
        th = 1000;
    }
    progressUnzip->setMaximum(totalBytes/th);
    progressUnzip->setValue(bytesRead/th);
}

// When unzip finished or canceled, this will be called
void MainWindow::unzipFinished()
{
    qDebug() << "Unzip finished.";
    progressUnzip->hide();
}

このコードでは、QProgressDialog は進行状況バーを表示せず、最後にファイルは解凍されません。

何か案が?

ご協力いただきありがとうございます、

4

1 に答える 1