[solved] Connectin Two DB at the same time
I'm tryng to connect a MySql database, select some data from different tables and then copy them on a PostgreSql database.
I'm doing the connection operation but i've some problem.
I'm connecting both db at the same time an i'm getting this errors:
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.
My mainwindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtSql>
#include <QtCore>
#include <QtGui>
#include <QDebug>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
my mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
db.setHostName("localhost");
db.setDatabaseName("vtigercrm540a");
db.setUserName("root");
db.setPassword("1234");
db.open();
db2.setHostName("localhost");
db2.setDatabaseName("prova");
db2.setUserName("postgres");
db2.setPassword("1234");
db2.open();
}
TIA
Re: Connectin Two DB at the same time
Pass distinct connection names to the two addDatabase() calls.
Cheers,
_
Re: Connectin Two DB at the same time
Solved
I've modiefied
db=QSqlDatabase::addDatabase("QMYSQL", "connection1");
db2=QSqlDatabase::addDatabase("QPSQL", "connection2");