Unsolved is it possible to pass a argument from signal to slot?
-
like
connect(this, SIGNAL(signal(int b)), this, SLOT(slot(int b)));slot(int b)
{ std::cout<<b<<std::endl; }I know there is a QSignalMapper, but it seems it's not gonna work if I want to pass a random argument, I have to set all the maps which could come up.
-
Hi,
You connection statement is wrong, remove b from it, only the type should be passed.
What do you mean by "pass random argument" ?
-
@SGaist hi, I mean if I do it with QSignalMapper, I can only pass the argument that are already set by the mapper.
So basically my question is if it's possible to pass arguments from signal to a slot directly.
I checked some sources and it seems it cannot be done this way.
-
What you are asking is not really clear. Can you show an example of what you want to achieve exactly ? With what you expect to get.
Because currently you seem to describe the standard signal and slot behavior. Meaning that if you take your original post sample code, calling for example
emit signal(5)
will give you5\n
on stdout. -
object1.cpp
int a = func();
connect(Object1, SIGNAL(signal(a)), Object2, SLOT(slot(a)));object2.cpp
slot(a)
{
//something happened with a as argument
} -
No, that's not how it's working.
See the Signals and Slots chapter of Qt's documentation.