Tutorial :Beginner Qt signals and slots question



Question:

I've just started learning Qt, which is my first experience with GUIs. So far it's just been console apps, and a bit of SDL.

I'm getting very confused with this whole signals and slots thing. I've just finished Tutorial 11. When you press shoot, the shoot button sends a signal, which is connected to the slot in the Cannonfield, for the "shoot" function. The shoot function starts a timer, which emits a signal every 5 ms to tell the shoot to move forward a frame. I get all that.

I experimented with putting a 0 to 999 for loop, which sent i to the application output so I could see what happened. This is where I start getting confused. Sometimes, it starts printing out 0, 1, 2, 3 etc, get a few in (say 10) then fires the shot, then when the shot goes off the screen, it prints the remainder up to 999. Other times it prints nothing, fires the shot, then prints 0 to 999. Other times it prints everything, then fires the shot. Am I just confusing myself by watching the output in Qt Creator at the same time as my program's running?


Solution:1

This is a problem with message loop based frameworks where everything is done in a single main thread. Please see my answer to a similar question here.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »