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.
Code:
//doesn't work as protected
if(ui.comboBox->receivers(SIGNAL(currentIndexChanged(int)))
QObject::connect(ui.
comboBox,
SIGNAL(currentIndexChanged
(int)),
this,
SLOT(comboBoxchanged
(int)))
Any ideas how I could I would be able to check for duplicate connections for these ui objects?
Re: duplicate signal/slot connections check
maybe you could disconnect the signal first? then you can be sure there is no connection ;)
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.
Re: duplicate signal/slot connections check
Quote:
(...) 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.
Re: duplicate signal/slot connections check
What is wrong with using the 4th or 5th argument to connect() and setting it to Qt::UniqueConnection?
Re: duplicate signal/slot connections check
Quote:
Originally Posted by
ChrisW67
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.
Re: duplicate signal/slot connections check
My bad, missed that in your original post.