Qt-interest Archive, November 2007
Initializing per-thread DB connection ?
Message 1 in thread
I want to construct a number of threads, each with their
own DB connection. My initial thought was to do something
like this:
class Thread: public Qthread, ...
{
public:
Thread();
...
private:
const QSqlDatabase db;
}
Thread::Thread : db(QSqlDatabase::addDatabase(..))
{
...
}
but this fails at run time, as QSqlDatabase can't find
the database drivers due to the lack of a QCoreApplication
object.
Is there any way round this ? I guess I can pass in a
QSqlDatabase object to the constructor at thread creation
time, but that is slightly clunky, and I'd rather keep all
of the thread internals hidden away, if possible.
Any suggestions ?
--
[ signature omitted ]