[Qt-interest] Sqlite multithreaded application
Jeremy Lainé
jeremy.laine at bolloretelecom.eu
Wed Oct 26 09:26:41 CEST 2011
Your method looks strange, it's never returning the database connection you just created so it will just get destroyed once the method returns.
> static bool createDbConnection(){
> QPluginLoader loader("qsqlite4.dll");
> QObject *plugin = loader.instance();
> if (!plugin)
> return false;
> QSqlDriverPlugin *sqlPlugin = qobject_cast<QSqlDriverPlugin *>(plugin);
> if (!sqlPlugin ) {
> QMessageBox::warning(0, "SQL plugin", "Loading failed", QMessageBox::Ok);
> return false;
> }
> QSqlDatabase db = QSqlDatabase::addDatabase(sqlPlugin->create("QSQLITE"));
This all looks rather complicated and "qsqlite4.dll" is definitely not cross-platform. Why didn't you stick to:
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
if (!db.isValid()) {
// no valid driver, report error
}
> Now, How do you think I may use the cloneDatabase() method? at time of db.open() method? I've understood correctly your suggest?
If you are not doing multithread, you won't have concurrent access to the database so I don't see any compelling reason to create multiple connections using cloneDatabase(). You can just pass the QSqlDatabase object around.
I would recommend you look at the documentation and examples, as I don't quite understand what you're trying to do.
PS: http://lists.qt-project.org/mailman/listinfo/interest
--
Jeremy LAINE
Bolloré telecom | 26, rue de Berri | F-75008 Paris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20111026/d70d80f5/attachment.html
More information about the Qt-interest-old
mailing list