QAmqpChannelHash: Tweak channelDestroyed.

- DON'T rely on sender()
- DON'T expect to be able to cast the QObject to a QAmqpChannel and have
  name() work.

This isn't as efficient as I'd like, but it doesn't crash either.
This commit is contained in:
Stuart Longland 2015-04-10 09:29:31 +10:00
parent ae4f1b336e
commit 31f90a17a0
2 changed files with 12 additions and 15 deletions

View File

@ -62,17 +62,16 @@ void QAmqpChannelHash::put(QAmqpQueue* queue)
} }
/*! /*!
* Handle destruction of a channel. Retrieve its current name and * Handle destruction of a channel. Do a full garbage collection run.
* remove it from the list, otherwise do a full garbage collection
* run.
*/ */
void QAmqpChannelHash::channelDestroyed() void QAmqpChannelHash::channelDestroyed(QObject* object)
{ {
QAmqpChannel* ch = static_cast<QAmqpChannel*>(sender()); QList<QString> names(channels.keys());
if (!channels.contains(ch->name())) QList<QString>::iterator it;
return; for (it = names.begin(); it != names.end(); it++) {
if (channels[ch->name()] == ch) if (channels.value(*it) == object)
channels.remove(ch->name()); channels.remove(*it);
}
} }
/*! /*!
@ -91,8 +90,8 @@ void QAmqpChannelHash::queueDeclared()
*/ */
void QAmqpChannelHash::put(const QString& name, QAmqpChannel* channel) void QAmqpChannelHash::put(const QString& name, QAmqpChannel* channel)
{ {
connect(channel, SIGNAL(destroyed()), connect(channel, SIGNAL(destroyed(QObject*)),
this, SLOT(channelDestroyed())); this, SLOT(channelDestroyed(QObject*)));
channels[name] = channel; channels[name] = channel;
} }

View File

@ -62,11 +62,9 @@ public:
private Q_SLOTS: private Q_SLOTS:
/*! /*!
* Handle destruction of a channel. Retrieve its current name and * Handle destruction of a channel. Do a full garbage collection run.
* remove it from the list, otherwise do a full garbage collection
* run.
*/ */
void channelDestroyed(); void channelDestroyed(QObject* object);
/*! /*!
* Handle a queue that has just been declared and given a new name. The * Handle a queue that has just been declared and given a new name. The