Results 1 to 4 of 4

Thread: dialog requires two button clicks to activate a search

  1. #1
    Join Date
    Jun 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default dialog requires two button clicks to activate a search

    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.

    Qt Code:
    1. void SearchDialog::on_btnSearchDialog_clicked()
    2. {
    3.  
    4. connect(ui->btnSearchDialog, SIGNAL(clicked(bool)), this, SLOT(startSearchRequest()));
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: dialog requires two button clicks to activate a search

    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.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: dialog requires two button clicks to activate a search

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Jun 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: dialog requires two button clicks to activate a search

    Thanks for the replies and information, I am now implementing separately.

Similar Threads

  1. Replies: 7
    Last Post: 17th March 2020, 13:13
  2. button activate
    By askatuak in forum Qt Quick
    Replies: 1
    Last Post: 27th September 2013, 09:54
  3. Replies: 2
    Last Post: 26th April 2011, 12:44
  4. Replies: 2
    Last Post: 31st July 2009, 21:30
  5. How to make Search Dialog as it is used by MAC O.S
    By merry in forum Qt Programming
    Replies: 5
    Last Post: 24th June 2008, 10:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.