creating signals with button slots
-
I have a Button : Button *plus = createButton(tr("+"), SLOT(additiveOperatorClicked())); in which the additiveoperatorclicked is a function I have to create signal slot connection can it be made.
-
Yes, but you'll need to add a pointer to the object that has the slot as additional parameter to the
createButton
function, because that's needed for theconnect
call. -
@Chris-Kawa can you please explain me how to do that because i am in the learning phase.
-
can you please explain me how to do that because i am in the learning phase.
-
If you want to connect your
plus
button to youradditiveOperatorClicked
function:connect(plus, SIGNAL(clicked()), this, SLOT(additiveOperatorClicked()));
-
@shravan_121 Well, assuming your
Button
class has aclicked()
signal you can do something like this:Button* createButton(const QString& text, QObject* obj, const char* slot) { Button* button = new Button(text); QObject::connect(button, SIGNAL(clicked()), obj, slot); return button; }
and assuming you have
some_object
that has aadditiveOperatorClicked()
slot you can use it like this:Button* plus = createButton("+", some_object, SLOT(additiveOperatorClicked()));