QProgressBar + std::thread

  • I have heavy task. I created QProgressBar for displaying that programm still work and runned heavy task in another thread using c++ std::thread class. But QProgressBar don't work, only window with QProgressBar starts, but QProgressBar don't appear in this window. Here is the code:

    QProgressBar progress;
    progress.setRange(0, 0);
    if (keyLength == 1024)
        std::thread(&RSA::generateKeys, &rsa, RSA::RSA_1024).join();
    else if (keyLength == 2048)
        std::thread(&RSA::generateKeys, &rsa, RSA::RSA_2048).join();

  • Lifetime Qt Champion


    From the looks of your progress bar is a local variable from your function so it will be destroyed at the end of the function hence no visibility.

Log in to reply

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