additional arguments to slot
-
Hi
I am struggling to get a grasp of how do this. I understand basic signal/slot architecture but cannot apply it to my use case.
I have a QWidget which displays certain information. The QWidget has a QPushButton. On clicking that button, I want to call some of my application (not-QT) functions and then display that in a display box.
I can of course call a plain function as follows:
void handleButton() { } QObject::connect(&button, &QPushButton::clicked, &handleButton);
But the "handleButton" function which I need to call takes many arguments (all of which will remain the same every time the button is clicked and not Qt related objects).
How can I achieve this?
Thanks
-
@over9000 When something emits a signal the arguments are routed to the slot, so it has to have the same or fewer number of arguments and they need to have matching type. If you don't care about the signal's arguments and want to call your slot with a fixed set of arguments you can wrap it in another function or a lambda:
void handleButton(int foo, const QString& bar) { ... } QObject::connect(&button, &QPushButton::clicked, [&](){ handleButton(42, "hello"); });
-
@Chris-Kawa brilliant, many thanks