Igor Mironchik schreef op 26-1-2014 16:29:
Hi.
I have some questions about database support in Qt 5.
First of all, is it safe to transfer a QSqlQuery instance from one
thread to another to process him in another thread. I.e. I want to
execute SELECT query on "DB" thread and return a QSqlQuery from that
thread to the GUI thread, where I will navigate and show users the
result of the query.
No, that is not safe. You can use database access from threads, but
every thread needs it own QSqlDatabase instance of the database
connection. The documentation states:
"A connection can only be used from within the thread that created it.
Moving connections between threads or creating queries from a
different thread is not supported."
(http://qt-project.org/doc/qt-4.8/threads-modules.html#threads-and-the-sql-module)
I will not use QSqlDatabase in another thread. I want to create
QSqlDatabase connection in worker thread and execute queries in that
thread... For SELECT statemetsa I want to return QSqlQuery object from
worker thread to the GUI one. Is it safe to use QSqlQuery in another
thread that created him?
--
Best Regards,
Igor Mironchik.
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest