What is the maximum number of QFuture<> :: QtConcurrent::run() can I create?

  • Hi guys. I have an application that reads and processes data in separate threads using QFuture and QtConcurrent run. Also I have some other questions I hope to discuss with you guys. Thanks!

    Q1) Would continuously creating multiple QFutures be an issue?

    • When work is finish, create another QFuture with some bools as a control.
    • As seen from the rough draft below of how my programme works.
    • Why I am asking this, is because every now and then, the results from my worker class returns me "wrong results." I also suspect that the main thread is causing interruptions in the QFuture thread?

    Q2) What is the difference in running applications with the debugger (CDB) as compared to executing the application without debugger?

    • Why I am asking this? Because when I run my application in debugger, I get "correct results". Whereas in debug/release, I think some of the functions or steps are skipped along the way, producing those "wrong results".
    //connect signals&slots
    connect(  &myClassObj, &myClass::WORKFINISH(int) , &this, &MainWindow::slot_work_done(int) );
    //the main gist of the programme in MainWindow
    READY = true;
      double* buffer = new double[1000]; //data
      fillBuffer(buffer);  //function to fill the data
         QFuture<void> futureOb = QtConcurrent::run( &myClassObject, &myClass::PROCESSdata, buffer); //do i need to handle destruction of this? 
          READY = false; //will not invoke another QFuture till current QFuture is done
      delete [] buffer;
    void MainWindow::slot_work_done(int x){
       ... //display results etc
       READY = true;

  • Lifetime Qt Champion


    From the looks of it, you'll be deleting buffer before it's processed. You should release it once you know the processing has been done so in PROCESSdata.

    By the way, why use QtConcurrent, if you only one want one PROCESSdata call at a time ?

  • @SGaist Hi SGaist, I am using QtConcurrent because the PROCESSdata takes anywhere between 2 to 15 seconds. It comprises of FFTs and other time consuming algorithms.

    Ah, the buffer is deleted before process. I will give it a fix. Thanks.

    However, with regards to why debugging mode produces different results. Do you have any ideas?

  • Lifetime Qt Champion

    Not the same way to initialise variables.

Log in to reply