I am a Qt beginer Quid,
The only thing I can think of is using a QThread, so that the application can kill the thread at some time.
Perhaps this wont work when the thread is doing a sql query - I really dont know if it would work or not.