Is it possible to change variables within a running function from the outside?

in order to make it easier to tell, I compressed the question.

has an interface where the following start function executes when the start button is clicked, and you can see that as long as paused is false, it will continue to execute. Because I added a CoreApplication::processEvents ();, inside it, the interface is still responsive now. When I press the pause button, the pause function is called and start exits. I tried it, and there was no problem, but I"m not sure if there are other dangers I haven"t seen yet.

int n = 1;

void start()
{
    while (1)
    {
        if (paused)
            return;

        qDebug() << nPP;

        QElapsedTimer timer;
        timer.start();
        while (timer.elapsed() <= 500)
            QCoreApplication::processEvents(); // 
    }
}

void pause()
{
    paused = true;
}
Qt
Mar.07,2021
Menu