Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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;
        sleep(1000);
    }
    
    Q_SLOT:
        void cancel_button(){
            future_.cancel();
        }
    

    Regards,
    Robin



  • 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.
    -Michael.



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


Log in to reply