[SOLVED] Sending a argument to a slot
-
I understand that i am not able to pass a argument to a slot that was not a argument of the signal.
However this is exactly what i want to be able to achieve. and im sure there must be a work around if anyone can help?basically when a button is pressed i want to send some text through to my slot function:
e.g
@QObject::connect(button, SIGNAL(clicked()),this, SLOT(updateL("C:/")));@regards, Tim.
-
Simply create a slot function without argument, connect your signal to this slot, in which your original slot get called as a normal function.
If you do not want to create a named function and your are using Qt5, you can connect your signal to the lambda function, in which you can call your original slot. [as kevlna65 suggested]
[quote author="Timmoth" date="1375433317"]I understand that i am not able to pass a argument to a slot that was not a argument of the signal.
However this is exactly what i want to be able to achieve. and im sure there must be a work around if anyone can help?basically when a button is pressed i want to send some text through to my slot function:
e.g
@QObject::connect(button, SIGNAL(clicked()),this, SLOT(updateL("C:/")));@regards, Tim.[/quote]
-
However i have an issue now, when i try to pass a Qstring through i get an error:
error: C3493: 'path' cannot be implicitly captured because no default capture mode has been specified
@
QString path = d.absoluteFilePath();
QObject::connect(button, &QPushButton::clicked, this{Hi(path);});
@
regards, TimEdit: please use @ tags around code sections; Andre
-
As d is a local variable you have tell the lambda how to capture it:
@
(1) auto l = &d { // only d is captured by reference };
(2) auto l = d { // only d is captured by value };
(3) auto l = & { // all local variables are captured by reference. };
(4) auto l = = { // all local variables are captured by value. (A copy will be made!) };
@There are several ways to combine different capture methods, refer to a c++ book of your choice for more details. (E.g. The C++ Programming Language 4, 11.4.3, page 293).