gustavospammo
8th May 2014, 15:35
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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtSql>
#include <QtCore>
#include <QtGui>
#include <QDebug>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
QSqlDatabase db;
QSqlDatabase db2;
};
#endif // MAINWINDOW_H
my mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
db=QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("vtigercrm540a");
db.setUserName("root");
db.setPassword("1234");
db.open();
db2=QSqlDatabase::addDatabase("QPSQL");
db2.setHostName("localhost");
db2.setDatabaseName("prova");
db2.setUserName("postgres");
db2.setPassword("1234");
db2.open();
}
TIA
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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtSql>
#include <QtCore>
#include <QtGui>
#include <QDebug>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
QSqlDatabase db;
QSqlDatabase db2;
};
#endif // MAINWINDOW_H
my mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
db=QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("vtigercrm540a");
db.setUserName("root");
db.setPassword("1234");
db.open();
db2=QSqlDatabase::addDatabase("QPSQL");
db2.setHostName("localhost");
db2.setDatabaseName("prova");
db2.setUserName("postgres");
db2.setPassword("1234");
db2.open();
}
TIA