QT Sql and Threads
This is my situation, requests are made through the browser to my application. Each request is handled by a different thread and in some cases these requests include INSERT, UPDATE, DELETE, in a sqlite database. What I do not understand is how to manage the connection to the db.
For each thread I have to use a new connection (and thus open-close connection) making sure that there are never two connections with the same name? Or should I create a single connection to the DB and I have to use a mutex to avoid concurrency issues? I'm using QTSql library and SQLite as database
Sorry for my bad english.
Connections can only be used from within the thread that did the creation. So I would highly discourage from using a single connection. It also depends on the database driver if it allows concurrent operations.
If you are using transactions you have to keep in mind that transactions for SQLite are not thread-safe in Qt by default (DEFERRED mode). You can init a thread safe transaction manually as far as I know (BEGIN IMMEDIATE TRANSACTION query).