mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 05:37:29 +02:00
Do not leak the Query object
This commit is contained in:
@@ -21,6 +21,7 @@ public:
|
|||||||
database->loadIndex();
|
database->loadIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Tomahawk::query_ptr query;
|
||||||
Tomahawk::dbcmd_ptr cmd;
|
Tomahawk::dbcmd_ptr cmd;
|
||||||
QSharedPointer<Tomahawk::Database> database;
|
QSharedPointer<Tomahawk::Database> database;
|
||||||
|
|
||||||
@@ -30,10 +31,16 @@ public slots:
|
|||||||
database->enqueue( cmd );
|
database->enqueue( cmd );
|
||||||
}
|
}
|
||||||
|
|
||||||
void onResults( const Tomahawk::QID, QList< Tomahawk::result_ptr> results )
|
void onResults( const Tomahawk::QID, const QList< Tomahawk::result_ptr>& results )
|
||||||
{
|
{
|
||||||
// TODO
|
// Query is destructed by deleteLater() so we need to wait for the
|
||||||
QMetaObject::invokeMethod( thread(), "quit", Qt::QueuedConnection );
|
// event queue to process it.
|
||||||
|
connect( query.data(), SIGNAL( destroyed( QObject* ) ),
|
||||||
|
thread(), SLOT( quit() ) );
|
||||||
|
|
||||||
|
// Remove references to local objects, so they are queued for destruction.
|
||||||
|
cmd.clear();
|
||||||
|
query.clear();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,8 +68,9 @@ int main( int argc, char* argv[] )
|
|||||||
tasks.moveToThread( &thread );
|
tasks.moveToThread( &thread );
|
||||||
|
|
||||||
// Load the Database
|
// Load the Database
|
||||||
Tomahawk::query_ptr query( Tomahawk::Query::get( "Bloc Party", QString() ) );
|
tasks.query = Tomahawk::Query::get( "Bloc Party", QString() );
|
||||||
Tomahawk::DatabaseCommand_Resolve* cmd = new Tomahawk::DatabaseCommand_Resolve( query );
|
tasks.query->moveToThread( &thread );
|
||||||
|
Tomahawk::DatabaseCommand_Resolve* cmd = new Tomahawk::DatabaseCommand_Resolve( tasks.query );
|
||||||
tasks.cmd = Tomahawk::dbcmd_ptr( cmd );
|
tasks.cmd = Tomahawk::dbcmd_ptr( cmd );
|
||||||
tasks.cmd->moveToThread( &thread );
|
tasks.cmd->moveToThread( &thread );
|
||||||
QObject::connect( cmd, SIGNAL( results( Tomahawk::QID, QList<Tomahawk::result_ptr> ) ),
|
QObject::connect( cmd, SIGNAL( results( Tomahawk::QID, QList<Tomahawk::result_ptr> ) ),
|
||||||
|
Reference in New Issue
Block a user