Unsolved Label change and corrosponding action on pushbutton
-
I want to add a pushbutton which can initiate or terminate the data processing. Initially label on button should be "initiate"-clicking on it starts prcessing. As this button is clicked label should change to " terminate". If terminate is clicked- it should stop processing of data and label on button should change to "initiate"....and so on.
Kindly suggest the solution..
Regards,
Anuj -
Hi
How do you interrupt the processing ?
Are you using threads or do you want to call a function repeatedly ?
If you are think about any kind of loop. that's not it. long lasting loops don't play well with GUI :)Can you tell about bit more about the processing?
You could use push buttons checkbox feature.
so when "down" it starts a time and in timers slot perform processing.
if unchecked, it calls timer stop. -
@mrjj Hi,
Here processing of data is reading data from file and plotting it. When clicked on initiate, starts plotting and changes the label to terminate. When terminate on same button is clicked, plotting is stopped and label of same button changes to initiate. -
Not super elegant but it works
connect(button,&QPushButton::clicked,this,[=]()->void{ const QString initiateText = tr("initiate"); if(button->text()==initiateText) button->setText(tr("terminate")); else button->setText(initiateText); });
EDIT:
See page 171 of C++ GUI Programming with Qt 4