D
D
dariasweetsun2021-04-12 21:21:17
Qt
dariasweetsun, 2021-04-12 21:21:17

How can I safely use a QSqlDatabase connection from different threads?

I have a DB connection instance ( QSqlDatabase ). I also have a main form on which, for example, there is a button for selecting a user's picture. How can I properly organize the loading of this image into the database? Obviously, in this main thread, where I have a GUI, it is wrong to do this, because the program window may freeze, although in fact the program just loads the picture and the window is "waiting" at that time.
As I understand it, you need to do this in a separate thread, but somewhere in the Qt documentation it says that " a QSqlDatabase connection can only be used from the thread that created it ". There is also an option to use mutexes and a static declaration, but I don’t fully understand what and how.

Please tell me how to be.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacob E, 2021-04-13
@dariasweetsun

What's the problem? There is a separate thread that works with the database, interaction with it goes through signals / slots that are thread-safe.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question