1

Topic: QSql and a multithreading

In what a singularity of operation with QSqlDatabse and QSqlQuery from other flow? At me it turns out so from the main (unique) flow all works; and if to transfer the code of performance of requests (QSqlQuery:: exec) in a worker thread (made purely that did not brake gui) that something falls. Can be eat any singularities of operation in a multi-threaded surrounding?

2

Re: QSql and a multithreading

Hello, x-code, you wrote: XC> In what a singularity of operation with QSqlDatabse and QSqlQuery from other flow? XC> at me it turns out so from the main (unique) flow all works; XC> and if to transfer code of performance of requests (QSqlQuery:: exec) in worker thread (made purely that did not brake gui) that something falls. XC> can be eat any singularities of operation in a multi-threaded surrounding? In each flow there should be a connection with a DB.

3

Re: QSql and a multithreading

Hello, Qt-Coder, you wrote: QC> In each flow there should be a connection with a DB. Anything to itself... That is if I do something in a flow, I should open connection with basis in this flow, there all make and then close connection? And it in spite of the fact that at all flows the general address space also is not present any competition for resources (simultaneously only one flow works with basis)? Why so? Still a question: it is such singularity Qt or MySQL? That is if to refuse from Qt' classes and to work directly with MySQL API that a problem remains or disappears?

4

Re: QSql and a multithreading

Hello, x-code, you wrote: XC> Still a question: it is such singularity Qt or MySQL? That is if to refuse from Qt' classes and to work directly with MySQL API that a problem remains or disappears? Singularity Qt. From the documentation: Threads and the SQL Module 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. In addition, the third party libraries used by the QSqlDrivers can impose further restrictions on using the SQL Module in a multithreaded program. Consult the manual of your database client for more information About MySql not in course.

5

Re: QSql and a multithreading

Hello, Qt-Coder, you wrote: QC> About MySql not in course. Made experiment, yes it and for mysql too. It is sad. It is necessary to alter architecture - to get a separate flow specially for operations from a DB, the flow should exist all time of existence of the program, have something like a cycle of reception of commands from other flows, process them and give results. All operations from a DB only through this interlayer. Can eat any ready decisions for this purpose? Or all to write from zero?

6

Re: QSql and a multithreading

Hello, x-code, you wrote: XC> Hello, Qt-Coder, you wrote: QC>> About MySql not in course. XC> made experiment, yes it and for mysql too. XC> It is sad. It is necessary to alter architecture - to get a separate flow specially for operations from a DB, the flow should exist all time of existence of the program, have something like a cycle of reception of commands from other flows, process them and give results. All operations from a DB only through this interlayer. XC> can eat any ready decisions for this purpose? Or all to write from zero? Yes there is a decision! There is a fine decision - the free library OTL: https://en.wikipedia.org/wiki/Oracle_Template_Library http://otl.sourceforge.net http://otl.sourceforge.net/otl3_intro.htm developed known  in the field of a DB Sergey Kuchin. It is now actual OTL v 4.0.412. Personally I use library OTL already almost 5 years!  OTL - much faster, than ODBC the driver and object of type QSqlDatabase from Qt. It not mere allegation, approximately was found out one year ago by this moment (if to whom interesting - I will share  and specific digits). About a multithreading: connection with a DB (connect to DSN) I do in a head (GUI-interface) flow after that I write (through INSERT) in other (working) flow where there is no operation cycle of messages - and all perfectly works. P.S. I work through OTL c a DB on MS a SQL Server (ODBC). Earlier, on a system to operation, worked through OTL with MySQL (also ODBC).  also OTL library in my own creative projects. So, if there will be questions - will be glad to help examples  OTL which at me collected much

7

Re: QSql and a multithreading

Hello, AlexGin, you wrote: AG> About a multithreading: connection with a DB (connect to DSN) I do in head (GUI-interface) a flow, AG> after that I write (through INSERT) in other (working) flow where there is no operation cycle of messages - and all perfectly works. Yesterday checked up is works (though like should not) and with Qt too. Does not work was specific with Embedded MySql: that in Qt that directly - if to create connection in one flow, and requests to fulfill from another something inside falls.

8

Re: QSql and a multithreading

Hello, x-code, you wrote: XC> Hello, AlexGin, you wrote: AG>> About a multithreading: connection with a DB (connect to DSN) I do in head (GUI-interface) a flow, AG>> after that I write (through INSERT) in other (the worker) a flow where there is no operation cycle of messages - and all perfectly works. XC> yesterday checked up is works (though like should not) and with Qt too. Does not work was specific with Embedded MySql: that in Qt that directly - if to create connection in one flow, and requests to fulfill from another something inside falls. Well about Embedded MySql something to tell difficult - I did not work with this system