PDA

View Full Version : Qpushbutton do something until click other button



isan
23rd April 2016, 05:42
I want to set two button start and stop ,if I click on start doing something until I click on stop button ,how can do this??
or if I have a checkBox until check doing something ,uncheck stop doing something??can show an example or related link??

Henry Blue Heeler
23rd April 2016, 11:34
Learn about signals and slots. QPushButton has a clicked() slot.

isan
23rd April 2016, 15:28
I know about clicked() I set Qpushbutton in gui and signal and slot auto-connected,when click start button do something once , i need once start click doing some thing until stop click,I read about press() and checked() but I don't find example for my need>

anda_skoa
23rd April 2016, 15:50
What is it that you want to continously do?

Is your question on how to call a slot continually?
If so, look at QTimer.

Cheers,
_

isan
23rd April 2016, 16:22
in the slot that connected to start Qpushbutton I want continuously to send and receive data over QTcpSocket and appanded receive data to QtextEdit and if stop click stop doing this

anda_skoa
23rd April 2016, 17:01
Well, then call connectToHost() in the start slot and disconnectFromHost() in the stop slot.

Cheers,
_

isan
23rd April 2016, 17:53
I can't do this because I have an other function do something over Qtcpsocket also in my program

anda_skoa
23rd April 2016, 18:44
I am afraid I don't understand.

How are you expecting a client socket to work if you don't let it connect to the server?

Cheers,
_

isan
23rd April 2016, 19:54
:D:D my mean I can't disconnectFromHost()

anda_skoa
24th April 2016, 09:32
Ah.
If you connect/disconnect in other places, then your start/stop slot could just set/unset a member variable (e.g. setting a bool member to true on start and to false on stop).
The slot that deals with incoming data then just need to check that value before adding text to the text edit, etc.

Cheers,
_

isan
25th April 2016, 17:24
I set timer in my pushbutton ,in start button start timer to send function every 3 second and stop button stop timer


connect(tm, SIGNAL(timeout()), this, SLOT(sninv());
tm->start(3000);
tnx..