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
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b385d0-2c11f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b385d0-2c11f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?