How do i use the buttons from a vector of objects that have a member QPushButton * button in my Widget class?
-
So i have a class Territory that has a member QPushButton * button and i have a class Game that inherits a QWidget, here i want the game to take place. This class has a vector of objects of type Territory. And my question is how i can use those buttons? That appear on the screen, but i don't know how to make a clicked() function that can be used by all of them. For example if i click a territory to color it another color. How can i do that?
-
So i have a class Territory that has a member QPushButton * button and i have a class Game that inherits a QWidget, here i want the game to take place. This class has a vector of objects of type Territory. And my question is how i can use those buttons? That appear on the screen, but i don't know how to make a clicked() function that can be used by all of them. For example if i click a territory to color it another color. How can i do that?
@Bebemc42
Hello and welcome.If you have a number of buttons and you wish them to share a single
clicked
signal you might consider grouping them in a QButtonGroup and attaching a slot to its QButtonGroup::buttonClicked(QAbstractButton *button) signal.Or you could iterate the vector calling
connect()
on each one in turn to the same slot, possibly with a parameter.