c++ - How to use QtConcurrent to qCompress on QByteArray? -


i want write little program compress files directory using qcompress of qbytearray.

however want run compression on multithreaded environment using qtconcurrent. have problems.

here code :

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 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); 

the problem compiler raise me errors

first : no matching function call filtered(&qbytearray,).

second : converstion qlist non scalar type qbytearray requested.

so, question is,is possible want?

thanks in advance

not sure, if qt4 can handle this.

qlist<qbytearray> list; ...add bytearrays list... auto wordmapfn  = [](qbytearray &arr){arr=qcompress(arr, 9);}; qfuture<void> f = qtconcurrent::map(list,wordmapfn); 

this compresses qbytearrays in list. if want keep uncompressed arrays, use mapped instead of map. wordmapfn has adjusted accordingly. if want compress single qbytearray qtconcurrent::run might more appropriate.

pay attention life time of list.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -