How can we pass arguments while implementing slots?
-
I have animate_button(bool); slots. I want while i am clicking a button i want to implement slot as animate_button(false);. I want something like this
@QObject::connect (button2, SIGNAL(clicked()), button2, SLOT(animate_button(false))); @ but it is not working. How can i do it? -
You can only use a slot with less parameters as the signal in your connect statement, so in this case none.
@QObject::connect (button2, SIGNAL(clicked()), button2, SLOT(animate_button()));@In your animate_button() slot you can set a variable to false
If you want to interact with the toggled state of a button you could use the signal "toggled":http://doc.qt.nokia.com/4.7/qabstractbutton.html#toggled
In that case you can pass a boolean
@QObject::connect (button2, SIGNAL(toggled(bool)), button2, SLOT(animate_button(bool)));@
I suggest you to read about "signals and slots":http://doc.qt.nokia.com/4.7/signalsandslots.html to understand the rules that apply.
-
If you don't want to use the checkable property of the button, your only way to achieve this is to keep the status of the animation (e.g., started = true|false) somewhere else, and each time you handle the clicked() signal you manually toggle the animation status. Another way is to provide two different slots, let say animation_start and animation_stop. In each slot you disconnect the slot itself from the signal handling and connect the other one, so each time the button is clicked one of the two slots handles the signal alternatively.