user1658435
user1658435

Reputation: 574

Using if statement

I want to display an image called image1 when a button1 is pressed and image2 when button2 is pressed. In order to do this I want to use 'if' statement. I wrote the following code:

if(ui->button1->clicked())
image.load(":/CondScrnIns.png");
else if(ui->button2->clicked())
image.load(":/CondScrnInsCentric.png");

but while executing these statements I'm getting the following error:

void QAbstractButton::clicked(bool) is protected

what function should I use insted of clicked()??

Upvotes: 1

Views: 4058

Answers (2)

dev
dev

Reputation: 2200

You will have to create slots for each buttons's clicked signal and the do image.load in there.

connect(button1, SIGNAL( clicked() ), this, SLOT(button1Clicked()));
connect(button2, SIGNAL( clicked() ), this, SLOT(button2Clicked()));

Then in button1Clicked() and button2Clicked() slots you can put in the code to load the image or resize the dialog box whatever you want.

Upvotes: 3

Osiris
Osiris

Reputation: 4185

You need to write the image.load() statements in the respective event handlers. You cannot check for button->clicked() in an if statement like that.

Look at this page: http://qt-project.org/forums/viewthread/2758

Upvotes: 0

Related Questions