PDA

View Full Version : dialog requires two button clicks to activate a search



xopherira
5th August 2016, 21:22
I have the following code on a dialog that is launched from a separate form. It works but requires two clicks to active. New to Qt and signal/slot metaphor, thanks form any help or suggestions.


void SearchDialog::on_btnSearchDialog_clicked()
{

connect(ui->btnSearchDialog, SIGNAL(clicked(bool)), this, SLOT(startSearchRequest()));

}

ChrisW67
5th August 2016, 23:06
This code is a slot that, because of its name, has automatically been connected to the clicked() signal of the button btnSearchDialog. When you click the button this code executes. You should call startSearchRequest() directly from this slot.

The connect() in your code is unecessary. If you were not relying on the autoconnected Designer UI this how you would connect the button to the startSearchRequest() slot...but it would be done once during UI object construction.

d_stranz
6th August 2016, 17:25
Moreover, as your code now stands, each time you click the button, it will add a new connection to startSearchRequest(). So the first time you click the button, nothing happens (as you observe) except that your code now makes a connection to the slot you actually want to execute. The second time you click the button both slots get executed, so not only does your search start, you also add another connection via the original on_btnSearchDialog_clicked() slot. So the third time you click the button, you now get two searches started plus you'll add yet another connection to the search slot. On the fourth click, three searches start, you add another connection... you see how it goes.

xopherira
8th August 2016, 14:20
Thanks for the replies and information, I am now implementing separately.