mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Do not rely on the object to be removed to be deleted after the callback
This commit is contained in:
@@ -19,11 +19,12 @@
|
|||||||
#include "WeakPeerHash_p.h"
|
#include "WeakPeerHash_p.h"
|
||||||
|
|
||||||
#include "PeerInfo.h"
|
#include "PeerInfo.h"
|
||||||
|
#include "utils/Closure.h"
|
||||||
|
|
||||||
#define WEAKPEERHASH_KEY "WeakPeerHashKey"
|
#define WEAKPEERHASH_KEY "WeakPeerHashKey"
|
||||||
|
|
||||||
WeakPeerHash::WeakPeerHash(QObject *parent)
|
WeakPeerHash::WeakPeerHash( QObject *parent )
|
||||||
: QObject(parent)
|
: QObject( parent )
|
||||||
, d_ptr( new WeakPeerHashPrivate( this ) )
|
, d_ptr( new WeakPeerHashPrivate( this ) )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -36,10 +37,10 @@ WeakPeerHash::WeakPeerHash( const WeakPeerHash &hash )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
WeakPeerHash::insert(const QString &key, const Tomahawk::peerinfo_ptr &value)
|
WeakPeerHash::insert( const QString &key, const Tomahawk::peerinfo_ptr &value )
|
||||||
{
|
{
|
||||||
value->setProperty( WEAKPEERHASH_KEY, key );
|
_detail::Closure* cl = NewClosure( value, SIGNAL( destroyed( QObject* ) ), this, SLOT( remove( QString ) ), key );
|
||||||
connect( value.data(), SIGNAL( destroyed( QObject* ) ), SLOT( remove( QObject* ) ) );
|
cl->setAutoDelete( true );
|
||||||
d_func()->hash.insert( key, value.toWeakRef() );
|
d_func()->hash.insert( key, value.toWeakRef() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,22 +51,7 @@ WeakPeerHash::hash()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
WeakPeerHash::remove( QObject *value )
|
WeakPeerHash::remove( const QString& key )
|
||||||
{
|
{
|
||||||
if ( value )
|
d_func()->hash.remove( key );
|
||||||
{
|
|
||||||
const QString key = value->property( WEAKPEERHASH_KEY ).toString();
|
|
||||||
d_func()->hash.remove( key );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Scan for null-Pointers
|
|
||||||
foreach ( QString key, d_func()->hash.keys() )
|
|
||||||
{
|
|
||||||
if ( d_func()->hash.value( key ).isNull() )
|
|
||||||
{
|
|
||||||
d_func()->hash.remove( key );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,7 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void remove( QObject* value );
|
void remove( const QString& key );
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE( WeakPeerHash )
|
Q_DECLARE_PRIVATE( WeakPeerHash )
|
||||||
WeakPeerHashPrivate* d_ptr;
|
WeakPeerHashPrivate* d_ptr;
|
||||||
|
Reference in New Issue
Block a user