Sample program to pass char array to qtConcurrent

  • Hello Everyone,
    Looking for a sample program to pass char array to QTConcurrent.
    I have a function which takes char array as an argument and need it pass to the function.
    I tried various ways of doing the same but no success.

  • Qt Champions 2018

    The problem is not passing it, it's keeping it alive until run finishes. Can you use QByteArray or std::array instead of the raw array?


    This is a bit awkward but it should work:

    // void doSomething(char* arr, int n)
    char myarray[100];
    const int arraySize = std::extent<decltype(myarray)>::value;
    char* arrayToPass = new char[arraySize];
    auto runWatcher =new QFutureWatcher<void>();
    QObject::connect(runWatcher,&QFutureWatcher::finished,[arrayToPass]()->void{delete [] arrayToPass;});

  • @VRonin : Thanks a lot. The implementation looks quite complex so moving with string instead of char array as you have mentioned in previous thread.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.