Unsolved Open MYSQL Database with connectionName
-
Yes but "OtherName" isn't the name that I have set with dbMyApp.setUserName("userName");
-
How did you setup the databases ?
Out of curiosity, why two different databases for your application ?
-
What do you mean by saying "setup" ?
MyApp
MyApp::MyApp(QQmlContext *ctx, QObject *parent) : QObject( parent) { QSqlDatabase::addDatabase("QMYSQL3", "myapp"); QSqlDatabase::addDatabase("QMYSQL3", "myclass"); MyClass *myClass = new MyClass(); ctx->setContextProperty("myClass", myClass); dbMyApp = QSqlDatabase::database("myapp"); dbMyApp.setHostName("localhost"); dbMyApp.setUserName("root"); dbMyApp.setPassword("mySQL:r00t"); dbMyApp.setDatabaseName("cube_application"); getDataMyApp(); }
MyClass
MyClass::MyClass(QObject *parent) : QObject(parent) { dbMyClass = QSqlDatabase::database("myclass"); dbMyClass.setHostName("localhost"); dbMyClass.setUserName("root"); dbMyClass.setPassword("mySQL:r00t"); dbMyClass.setDatabaseName("catalogue_4mod"); getDataMyClass(); }
I have two databases because data have no relationship. My application contains several "mini application".
-
I meant server side setup.
But again why multiple databases ? You can have your unrelated tables in only one database. They don't need to have any relation between them.
-
My database is only on localhost and create by command line.
Indeed the two database can be merged, I find it more clear like this (It is maybe a mistake) -
Do you mean you find it more clear to connect your application to two different databases ?
-
Yes, because my application is the merge of different application which has a data on database
-
That I understood, but still, deploying several databases for one application sounds like an overkill.
-
Ok, I will merge my two databases
-
In my app, the error
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work. QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
solves when pass the database on QSqlQuery constructor.
In your case could be something like QSqlQuery(dbMyClass) for querys on MyClass and QSqlQuery(dbApp) for querys on MyApp.