1

QByteArray の qCompress を使用して、ディレクトリからすべてのファイルを圧縮する小さなプログラムを書きたいと思います。

ただし、QtConcurrent を使用してマルチスレッド環境で圧縮を実行したいと考えています。しかし、私にはいくつかの問題があります。

ここに私のコード:

FilePool pool(folder,suffix);
QFutureWatcher<QString> watcher;
QProgressDialog progressDialog;


connect(&watcher,SIGNAL(progressRangeChanged(int,int)),&progressDialog,SLOT(setRange(int,int)));

connect(&watcher,SIGNAL(progressValueChanged(int)),&progressDialog,SLOT(setValue(int)));

connect(&progressDialog,SIGNAL(canceled()),&watcher,SLOT(cancel()));

QFuture<QString> future = QtConcurrent::filtered(pool,FindInFile(search));
QString text;

watcher.setFuture(future);

progressDialog.exec();

future.waitForFinished();
//Test for compressing file

QFile outFile("testCompress.ecf");
outFile.open(QIODevice::WriteOnly);
QByteArray nonCompressedData;
foreach(const QString &file,future.results()){
    //Fichier d'entrée
    QFile inFile(file);
    inFile.open(QIODevice::ReadOnly);
    nonCompressedData.append(inFile.readAll());
    inFile.close();
    text += file + "\n";
}

//QByteArray compressedData(qCompress(nonCompressedData,9));
//PROBLEM HERE
QFuture<QByteArray> futureCompressor = QtConcurrent::filtered(nonCompressedData,qCompress);
futureCompressor.waitForFinished();
QByteArray compressedData = futureCompressor.results();

outFile.write(compressedData);

問題は、コンパイラがエラーを発生させることです

最初:filtered(&QByteArray,)の呼び出しに一致する関数がありません。

2 番目: QList から非スカラー型 QByteArray への変換が要求されました。

だから、私の質問は、私がやりたいことをすることは可能ですか?

前もって感謝します

4

1 に答える 1