I'm trying to subclass QSqlTableModel so that the constructor will set up the database that is needed for the model.
My code looks something along the lines of:
MyClass::myClass( QObject* parent, QSqlDatabase data )
:QSqlTableModel(parent, data)
{
auto db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
if( !db.open() )
{
//Some debug info
}
if( !database().isOpen() )
{
// Some debug info that is called
}
qDebug() << database().connectionName();
qDebug() << db.connectionName();
}
Then the constructor will output:
""
"qt_sql_default_connection"
Why are the two databases not both connected to the default connection?