qtconcurrent cancel without leak memory

  • Hi,

    I create some resources with new command in heavy job and I want to cancel it. Is it possible to delete the pointer only if it was alocate?

    future_ = QtConcurrent::run(this, &Class::foo);
    Class::foo() {
        int* bar = new int;
        void cancel_button(){


  • Hi,
    AFAIK you cannot cancel QtConcurrent::run anyway, using future_.cancel().

    You can cancel only QtConcurrent computations that work on a container handling each of its members in a separate thread, as to cancel in QtConcurrent means to start no new threads anymore. It does not mean to stop already running threads.

  • Thank you for your reply. My button cancel unrun job and wait for running thread.

Log in to reply

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