bandwidthmanager: Fix unregistering devices on delete

from the destroyed signal, qobject_cast won't work because the object
is already destroyed. One must use reinterpret_cast then
This commit is contained in:
Olivier Goffart 2017-09-25 11:55:18 +02:00 committed by Roeland Jago Douma
parent 37810c0a19
commit fd9662b803
No known key found for this signature in database
GPG key ID: F941078878347C0C
2 changed files with 5 additions and 21 deletions

View file

@ -95,7 +95,7 @@ void BandwidthManager::registerUploadDevice(UploadDevice *p)
{
_absoluteUploadDeviceList.append(p);
_relativeUploadDeviceList.append(p);
QObject::connect(p, SIGNAL(destroyed(QObject *)), this, SLOT(unregisterUploadDevice(QObject *)));
QObject::connect(p, &QObject::destroyed, this, &BandwidthManager::unregisterUploadDevice);
if (usingAbsoluteUploadLimit()) {
p->setBandwidthLimited(true);
@ -111,14 +111,7 @@ void BandwidthManager::registerUploadDevice(UploadDevice *p)
void BandwidthManager::unregisterUploadDevice(QObject *o)
{
UploadDevice *p = qobject_cast<UploadDevice *>(o);
if (p) {
unregisterUploadDevice(p);
}
}
void BandwidthManager::unregisterUploadDevice(UploadDevice *p)
{
auto p = reinterpret_cast<UploadDevice *>(o); // note, we might already be in the ~QObject
_absoluteUploadDeviceList.removeAll(p);
_relativeUploadDeviceList.removeAll(p);
if (p == _relativeLimitCurrentMeasuredDevice) {
@ -130,7 +123,7 @@ void BandwidthManager::unregisterUploadDevice(UploadDevice *p)
void BandwidthManager::registerDownloadJob(GETFileJob *j)
{
_downloadJobList.append(j);
QObject::connect(j, SIGNAL(destroyed(QObject *)), this, SLOT(unregisterDownloadJob(QObject *)));
QObject::connect(j, &QObject::destroyed, this, &BandwidthManager::unregisterDownloadJob);
if (usingAbsoluteDownloadLimit()) {
j->setBandwidthLimited(true);
@ -144,8 +137,9 @@ void BandwidthManager::registerDownloadJob(GETFileJob *j)
}
}
void BandwidthManager::unregisterDownloadJob(GETFileJob *j)
void BandwidthManager::unregisterDownloadJob(QObject *o)
{
GETFileJob *j = reinterpret_cast<GETFileJob *>(o); // note, we might already be in the ~QObject
_downloadJobList.removeAll(j);
if (_relativeLimitCurrentMeasuredJob == j) {
_relativeLimitCurrentMeasuredJob = 0;
@ -153,14 +147,6 @@ void BandwidthManager::unregisterDownloadJob(GETFileJob *j)
}
}
void BandwidthManager::unregisterDownloadJob(QObject *o)
{
GETFileJob *p = qobject_cast<GETFileJob *>(o);
if (p) {
unregisterDownloadJob(p);
}
}
void BandwidthManager::relativeUploadMeasuringTimerExpired()
{
if (!usingRelativeUploadLimit() || _relativeUploadDeviceList.count() == 0) {

View file

@ -45,11 +45,9 @@ public:
public slots:
void registerUploadDevice(UploadDevice *);
void unregisterUploadDevice(UploadDevice *);
void unregisterUploadDevice(QObject *);
void registerDownloadJob(GETFileJob *);
void unregisterDownloadJob(GETFileJob *);
void unregisterDownloadJob(QObject *);
void absoluteLimitTimerExpired();