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

GUI Application Freezes when QButton is pressed



  • Hello All,
    This is a very common question though would, like to start something in relevance of the issue that haven't been answered.
    There is start button on my application. When i start the application my UI freezes until the operation
    is completed. What i have read that slots execute in parallell so why the application freezes.
    My slots takes approximately 10 sec to execute as it contains lot of initilaiztions.
    What would be correct way to handle such scenarios.


  • Lifetime Qt Champion

    @Kira said in GUI Application Freezes when QButton is pressed:

    What i have read that slots execute in parallell

    No, they don't. If you have a long lasting operation, then do not execute it in main thread (GUI thread) execute it in another thread.



  • @jsulm : Thanks for the reply. In my previous discussion over the forum i was having getting a time in main thread so i have got suggestion to save image using singnal/slot mechanism to save image because it would create a queued slot connection and images would be saved without getting a lag.
    So i got an impression that slot executes parallely.


  • Lifetime Qt Champion

    @Kira Yes, a signal is put into the queue and next time the event loop is executed the slot will be executed. But as soon as the slot is started it blocks the event loop until it finishes. So, if it needs a lot of time your UI will be blocked until it is finishes. In that time no other slots can be executed. A thread can't execute more than one method/function at the same time. That's why long lasting operations are usually moved to other threads and are not executed in the main thread.



  • @jsulm : Thanks for the clarity was very helpful


Log in to reply