Qt program freezes (doesn't respond) Until the function ends, it starts working again

I have a UI application in Qt, I have several functions that run large scale SQL queries that return thousands of results.

when the button that launches this request clicks the windows of the user interface, it instantly switches to “not responding”, however, I see on the console outputs that everything is still working in the background. As soon as the function ends, data is displayed as expected, and the user interface reacts again and is fully operational.

I know that this is due to the fact that the function loops thousands of times due to the large number of results, but I was hoping that I could just put it in the loading bar, which progresses as the search does, and not just block the window, forcing its look like the program crashed. AFAIK I don't have leeks, so does anyone have any suggestions?

oh also im thinking that this is not a lack of memory, because when I click this button, the task manager shows only a couple of MB of memory that are used for this process, and the processor in no way maximizes either

+5
source share
2 answers

, , , , . , . , (, ..), .

, , . , , , , , " ".

+3

, , QCoreApplication:: processEvents(). :

void slowFunction()
{
    lostOfResults = makeSqlQuery(...); // quite fast
    for (r in lostOfResults)
        doSomethingWithResult(r); // one call is quite fast
}

SQL- doSomethingWithResult() , QCoreApplication:: processEvents() :

void slowFunction()
{
    lostOfResults = makeSqlQuery(...);
    for (r in lostOfResults) 
    {
        doSomethingWithResult(r);
        QCoreApplication::processEvents();
    }
}

GUI . SQL- ( ), . .

+5

All Articles