I have a simple GUI:
A QPushButton, when clicked, a number (say 11) shall be shown (I use a QLCDnumber for this). When clicked again another number shall be shown (say 10).
My aim is to use the QAbstractButton::toggled ( bool checked ) feature for this.
As I learned, a proper signal-slot-connection could look like this:
connect(ui.startstopButton, SIGNAL(toggled(bool)), thread, SLOT(start()));
(I additionally use threads but they're not the problem)
My question: How can I differ between "the button is toggled" (checked = true) and "the button is not toggled" (ckecked = false) in my signal-slot-statement?
I used variations like SIGNAL(toggled(bool = true)), SIGNAL(toggled(bool checked = true)) or SIGNAL(toggled(true)) but neither is working. I allways get the debugger message:
Object::connect: No such signal QPushButton::toggled(bool = true) in testthread.cpp:15
Object::connect: (sender name: 'startstopButton')
I definitely have enabled setCheckable of my button.
The signal is just toggled(bool), the receiving end will has a bool parameter too:
connect(ui.startstopButton, SIGNAL(toggled(bool)), thread, SLOT(start(bool)));
This way the boolean value sent by the toggle signal, will be received by the slot. In the slot function, you can check if the received boolean is true or not.
Here is assumed that the thread:start() is some function you actually wrote, if not, create a new slot which will check the value of the boolean, and then start the thread.
connect(ui.startstopButton, SIGNAL(toggled(bool)), threadStarter, SLOT(start(bool)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With