Results 1 to 7 of 7

Thread: duplicate signal/slot connections check

  1. #1
    Join Date
    Nov 2009
    Posts
    14
    Thanks
    4

    Default duplicate signal/slot connections check

    I want to prevent a connection between a ui object signal and a slot from occurring if there is already an existing connection.

    I can't use Qt::UniqueConnection due to only being able to use 4.5.x, and I can't use QObject::receivers() as a condition in an if statement because it is a protected function.

    Qt Code:
    1. //doesn't work as protected
    2. if(ui.comboBox->receivers(SIGNAL(currentIndexChanged(int)))
    3. QObject::connect(ui.comboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboBoxchanged(int)))
    To copy to clipboard, switch view to plain text mode 

    Any ideas how I could I would be able to check for duplicate connections for these ui objects?

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: duplicate signal/slot connections check

    maybe you could disconnect the signal first? then you can be sure there is no connection

  3. #3
    Join Date
    Nov 2009
    Posts
    14
    Thanks
    4

    Default Re: duplicate signal/slot connections check

    I did disconnect the signal, but then some code follows which I can't assure will reconnect or not, and then this code is run which needs to assure a non-duplicate connection, otherwise my slot will evoked multiple times.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: duplicate signal/slot connections check

    (...) but then some code follows which I can't assure will reconnect or not (...)
    So recreate the connection after this code. Another way is to subclass QComboBox, this way you can use the "receivers()" method.

  5. #5
    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: duplicate signal/slot connections check

    What is wrong with using the 4th or 5th argument to connect() and setting it to Qt::UniqueConnection?

  6. #6
    Join Date
    Nov 2009
    Posts
    14
    Thanks
    4

    Default Re: duplicate signal/slot connections check

    Quote Originally Posted by ChrisW67 View Post
    What is wrong with using the 4th or 5th argument to connect() and setting it to Qt::UniqueConnection?
    Nothing is wrong with that, but the Qt version I am using is only 4.5.x which doesn't have that feature.

    I ended up just using blocksignals() instead of disconnecting/reconnecting, as I just wanted to block the signals from triggering the slots when I was programatically setting values for my ui objects. Thanks for your help.

  7. #7
    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: duplicate signal/slot connections check

    My bad, missed that in your original post.

Similar Threads

  1. Debugging singal-slot connections
    By gnik in forum Qt-based Software
    Replies: 0
    Last Post: 11th July 2009, 19:50
  2. Queued Signal Slot connections
    By SebastianBecker in forum Qt Programming
    Replies: 2
    Last Post: 24th June 2009, 20:06
  3. Replies: 2
    Last Post: 12th February 2009, 22:23
  4. Replies: 2
    Last Post: 20th September 2007, 12:27
  5. Signal/slot connections of deleted items
    By Michiel in forum Newbie
    Replies: 2
    Last Post: 24th March 2006, 16:44

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.