[Qt-interest] Sqlite multithreaded application
Michele Ciampichetti
cia.michele at gmail.com
Wed Oct 26 10:01:41 CEST 2011
My method use the plugin Approach to port the QSqlite4.dll out of QT path:
the machine in which I install my application haven't got the QT Sdk
installed, and if I use your sugger, I've an error because the usual QT path
for sqldrivers not exist! (Qt/4.7.2/plugins/sqldrivers ecc...)
So I must use the plugin approach to "connect" the Qsqlite4.dll library to
the rest of executable.
Do you think this could be my problem?
Also If I don't use thread, I could have concurrent access to database,
because, the same application is runned by different PC that all connect to
the same database stored in a network device.
Do you think this could create concurrent access and any problem?
Thanks for your time and for the link. I'll use it soon.
Michele
2011/10/26 Jeremy Lainé <jeremy.laine at bolloretelecom.eu>
>
> 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/f5731376/attachment.html
More information about the Qt-interest-old
mailing list