void SomeClass::mySlot(MyClass *var){
...
}
void SomeClass::SomeFunction(){
MyClass *myVar;
QPushButton *button = new QPushButton(this);
connect(button, SIGNAL(clicked()), this, SLOT(mySlot(myVar)));
}
I want mySlot to receive myVar when the button is clicked.
is it possible to do something like that? I don’t want to store myVar pointer in SomeClass.
update (my solution):
void SomeClass::mySlot(){
QPushButton *button = static_cast<QPushButton*>(sender());
MyClass *myVar = qobject_cast<MyClass*>(qvariant_cast<QObject *>(button->property("myVar")));
...
}
void SomeClass::SomeFunction(){
MyClass *myVar;
QPushButton *button = new QPushButton(this);
button->setProperty("myVar", QVariant::fromValue((QObject*)myVar));
connect(button, SIGNAL(clicked()), this, SLOT(mySlot()));
}
No it is not possible. You can use a slot which discard some parameters but not a slot which have more parameters than the signal. Plus you cannot pass a variable when connecting a slot.