QSqlquery exec and prepare sometimes stuck
I'm facing the following problem:
I have addDatabase in the constructor of my class. I run with qtconcurrent a function that opens the database. The database object is in a variable that called db. When i call another function that executes a query in the db the code stuck. I found that the problem is with exec or with the prepare. This is not happens all the time. Sometimes after a few calls of the same function the code stuck.
I run with qtconcurrent a function that opens the database.
How and why?
The code of establishing connection is:
QFuture<void> future = QtConcurrent::run(this, &DatabaseManager::establish_connection);
I'm using qtconcurrent because the connection stuck my interface untill database open and this is not very good for my application.
DatabaseManager::establish_connectiondo? Also are you making sure you don't access the database before the job has finished?
This function sets the hostname, username and password of the database and the opens it. Nothing more. The addDatabase is not in this function in order to be able to use the database instance from every part of my code.
I think you either have some strange race condition, or the connection to the database is dropped/busy so the