PDA

View Full Version : Incorporating if-else statement with QPushButton



JonSim
23rd January 2016, 08:10
Hi guys, anyone know how to incorporate QPushButton into if-else statment?
I am using connect function for my program.
I do not know how to let the QPushButton work if it is clicked.


iampushbutton = new QPushButton;

if(iampushbutton->_____?______ )
{
function1();
}
else
{
function2();
}

anda_skoa
23rd January 2016, 10:23
What is it that you want to check?
I.e. what should the if condition mean?

Cheers,
_

d_stranz
24th January 2016, 00:14
I am using connect function for my program.

If you are using a connect() statement with the correct syntax and you have correctly implemented the slot to handle the button's clicked() signal, then your slot is being called when the button is clicked. You implement the code for what happens next inside the slot method.

If you don't understand that, then you need to study the example and tutorial programs that came with your Qt distribution and read about signals and slots. There are dozens of examples of how push buttons and their signals are used.