How can I correctly manage MySQL database connections across threads in Qt?
According to Qt themselves
A database connection must only be used from within the thread that created it. Moving a connection into another thread can be done with QSqlDatabase::moveToThread().
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
https://doc.qt.io/qt-6/threads-modules.html#threads-and-the-sql-module
What are the differences between these two QSqlDatabase declaration methods?
One of the 2 accepts connectionName as an argument
Adds a database to the list of database connections using the driver type and the connection name connectionName. If there already exists a database connection called connectionName, that connection is removed.
The database connection is referred to by connectionName. The newly added database connection is returned.
If type is not available or could not be loaded, isValid() returns false.
If connectionName is not specified, the new connection becomes the default connection for the application, and subsequent calls to database() without the connection name argument will return the default connection. If a connectionName is provided here, use database(connectionName) to retrieve the connection.