Sample program to pass char array to qtConcurrent
Solved
General and Desktop
-
The problem is not passing it, it's keeping it alive until
run
finishes. Can you useQByteArray
orstd::array
instead of the raw array?EDIT:
This is a bit awkward but it should work:
// void doSomething(char* arr, int n) char myarray[100]; std::fill(std::begin(myarray),std::end(myarray),'A'); /////////////////////////////////////////////////////////////// const int arraySize = std::extent<decltype(myarray)>::value; char* arrayToPass = new char[arraySize]; std::memcpy(arrayToPass,myarray,arraySize); auto runWatcher =new QFutureWatcher<void>(); QObject::connect(runWatcher,&QFutureWatcher::finished,runWatcher,&QFutureWatcher::deleteLater); QObject::connect(runWatcher,&QFutureWatcher::finished,[arrayToPass]()->void{delete [] arrayToPass;}); runWatcher->setFuture(QtConcurrent::run(std::bind(doSomething,arrayToPass,arraySize)));