My application has a main window, with a read only model to the database, edit windows, with read/write models, a scraper (in main thread) that edits the database with QSqlQuery and a scanner (seperate thread), that updates data with QSqlQuery from a seperate QSqlDatabase.

Now this should be threadsafe, I'm using sqlite3, and it I have seperate QSqlDatabase connections for the main thread and the scanner, however I'm getting the occasional "database is locked". Which isn't really an error, as far as I can tell it's just another connection using it.

The question is how I can work around it? I was hoping to set sqlite3_busy_timeout() to a few seconds (as no query should take longer), but it doesn't seem to be possible with Qt's sql drivers.

I'm also consider using a QMutex to lock access to the database, the problem is I'm not entirely sure where I need to lock.
For example in transactions in the scanner thread, should I:
1 : lock before the transaction, unlock after
2 : Lock before commit, unlock after.
3 : Lock before UPDATE/INSERT in the transaction, and unlock after.

Of course keeping the lock from start of transaction to the end of "safest", there's a good chance that'll lock up my gui :/