You do it exactly the same way you handle multiple database connections to other databases.
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QStringList>
#include <QDebug>
int main(int argc, char **argv)
{
db1.setDatabaseName(":memory:");
if (db1.open()) {
qDebug() << "db1 open";
QSqlQuery qry
("CREATE TABLE test1 (a integer)", db1
);
qDebug() << "Tables in db1" << db1.tables();
}
db2.setDatabaseName(":memory:");
if (db2.open()) {
qDebug() << "db2 open";
QSqlQuery qry
("CREATE TABLE test2 (a integer)", db2
);
qDebug() << "Tables in db2" << db2.tables();
}
return 0;
}
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QStringList>
#include <QDebug>
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QSqlDatabase db1 = QSqlDatabase::addDatabase("QSQLITE", "conn1");
db1.setDatabaseName(":memory:");
if (db1.open()) {
qDebug() << "db1 open";
QSqlQuery qry("CREATE TABLE test1 (a integer)", db1);
qDebug() << "Tables in db1" << db1.tables();
}
QSqlDatabase db2 = QSqlDatabase::addDatabase("QSQLITE", "conn2");
db2.setDatabaseName(":memory:");
if (db2.open()) {
qDebug() << "db2 open";
QSqlQuery qry("CREATE TABLE test2 (a integer)", db2);
qDebug() << "Tables in db2" << db2.tables();
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks