I'm currently working on a game with a friend of mine, and now we are kind of stuck. We need to pass two arguments to a slot. I want to use one slot for two buttons, and one of the buttons will be used for adding, and the other one for subtracting. This will be one of the arguments, either 0 (for subtracting) or 1 (for adding). The other argument will be a kind of ID, because i will have several sets of these two buttons. I've used several other slots in my code, and on these slots I've been using QSignalMapper like this:
Button * button = new Button(argument1, argument2, argument3);
int num = 1;
QSignalMapper * signalMapper = new QSignalMapper(this);
connect(button, SIGNAL(clicked()), signalMapper, SLOT(map)));
signalMapper->setMapping(button, num);
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(mySlot(int)));
scene->addItem(button);
Is there any way I can pass two arguments to a slot?
QSignalMapper
has a single parameter only. But you can use one of the following ways to split buttons into the several sets:QString
where you can use some token to split a set number from a button number, i.e.1;2
(the first set, button ID = 2) usingQString::split()
.Example of the slot: