Qt World Summit: Register Today!

Controlling infinite loop with button click - Qt

  • Consider I have two buttons "start" and "end", and a slot "start_game()". The method "start_game()" looks like:

    void start_game()
           //an infinite loop that refreshes(re-paints) a widget
           while(/*some flag maybe*/)
                     //update paint widget
                     //exit when "end" button is clicked

    I can easily connect "clicked(bool)" signal of the "start" button with above method containing infinite loop. I could not understand how can I control this loop, for example I want to exit this loop on "end" button's click. I understand that the loop blocks the main event loop. What is the efficient wat of getting such functionality.

    Best regards

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Since your comment is update paint widget, why do you need such a loop ?

Log in to reply