Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 13
Registered: ‎10-05-2012
My Device: BB 10 dev Alpha
My Carrier: BSNL

SQLite Database in multithreading.

 have small messaging application where each message data is stored in SQLite Database.
 We update database on every send/receive message as well as simultaneously update UI with database attribute.
 While doing this we are facing a CRASH.

After trying lots of things we solve problem using static variable of database

like bellow.

QSqlDatabase MyDatabase::messagDb= QSqlDatabase::addDatabase("QSQLITE", "message");

we never close database connection, and do all operation on database in single theread that is synchronous. In UI thread.

This thing is work fine except we see sufficient amount of lag in our application because of database operation in UI Thread.

Is there a way we can do multiple thread or implement database connection pool ?

that can achieve both synchronous and asynchronous database operations.

Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: SQLite Database in multithreading.

this should help:
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Posts: 13
Registered: ‎10-05-2012
My Device: BB 10 dev Alpha
My Carrier: BSNL

Re: SQLite Database in multithreading.

Thanks for reply


I tried  that before it before.


What happen when I use SqlConnection 

its ok to  storing received message or task that not need to be done in asynchronous  but when i some operation like before saving message i have to check user status in sychronous way meanwhile if some task in running  in background by SqlConnection that synchronous operation give sqlite busy error and app crashes.                               








Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

Re: SQLite Database in multithreading.

I really advise against use synchronous database operation. Just start the operation and wait for the proper signal to signal that the data is ready.

BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!