O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What just happened?

First, we added a setupRod() helper function that creates a new rod and connects its signal to the new rodClicked() function. Then we simply called setupRod() for each index and accumulated the rod object into the rods array. The rodClicked() function will contain the rest of our game logic, but for now it only prints the index of the clicked rod to the application output.

Note that the content of the setupRod() function cannot be placed directly into the body of the for loop over iThe clicked() signal is connected to a closure that captures the rod variable. Within the function, each rod will connect to a closure that captures the corresponding Rod object. Within the for loop, all closures would capture the common

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required