Code:
connect( button, SIGNAL(clicked()), this, SLOT( on_button_clicked())); This::on_button_clicked() { button->setEnabled(false); }
this does not work, of course. how to implement to disable a button when it is clicked?
Printable View
Code:
connect( button, SIGNAL(clicked()), this, SLOT( on_button_clicked())); This::on_button_clicked() { button->setEnabled(false); }
this does not work, of course. how to implement to disable a button when it is clicked?
does ur cod reach the slot ?
Are you using your own slot ? or is it the default slot : on_XXXX_clicked() ?
BTW, how do you plan to enable it again ? bec you wont be able to click a disabled button ;)
try this
Code:
connect(button, SIGNAL(clicked(bool)), button, SLOT(setEnabled(bool)));
the setEnabled() kind of functions do not reflect the change till the slot is complete and control goes back to event loop. and as explained below by others, if the only thing you have to do is to disable/enable the button, best is to connect it to the button's slot
cheers!
i created a test project like this:
Code:
connect(ui.btn, SIGNAL(clicked()), this, SLOT(on_btn_clicked())); connect(ui.btn_2, SIGNAL(clicked()), this, SLOT(on_btn_2_clicked())); //... THIS::on_btn_clicked() { ui.btn->setEnabled(false); ui.btn_2->setEnabled(true); } THIS::on_btn_2_clicked() { ui.btn_2->setEnabled(false); ui.btn->setEnabled(true); }
and it works well. my connections are more complicated: like this:
Code:
//calendar is a QCalendarWidget, currentPageChanged(int, int ) is it's signal, this signal is //often emitted the same time the QPushButton prevMonth and nextMonth is clicked //currentPageChagned(int,int ) is not triggered by the buttons' clicking //on_currentPage_changed(int, int) is my slot void MyWidget::on_currentPage_changed(int, int) { prevMonth->setEnabled(false); nextMonth->setEnabled(true); }
Looks, like you could have a look at QWizard...
Lykurg