Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

qt_sql_default_connection' is still in use --- again

$
0
0
Hi I’m developing a small daemon, which at regular intervals (many times every hour) opens a database connection, inserts some records, and closes the connection again. Everything works great, except every time the database connection is closed, I get the very well known “qt_sql_default_connection’ is still in use” message, some small memory leak and an open connection to the database (after some time I get “Too many connections QMYSQL:”). The funny thing is : I do not have to use any query to get the error, all I have to do, is to connect to the database, and disconnect again! I have made this small test program, which also displays the error. I have a form with two buttons, one for connect, one for disconnect. #include "mainwindow.h" #include "ui_mainwindow.h" #include <QSqlDatabase>   MainWindow::MainWindow(QWidget *parent) :     QMainWindow(parent),     ui(new Ui::MainWindow) {     ui->setupUi(this); }   MainWindow::~MainWindow() {     delete ui; }   void MainWindow::on_pushButton_clicked()  // connect {     QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");     db.setHostName("localhost");     db.setDatabaseName("test");     db.setUserName("user");     db.setPassword("pwd");     db.open(); }   void MainWindow::on_pushButton_2_clicked()  // disconnect {     QSqlDatabase::database().close();     QSqlDatabase::removeDatabase(QSqlDatabase::database().connectionName()); } Any ideas ? I’m using QtCreator 5.1 and mysql 5.5.32 on Ubuntu 64 bit. Kim

Viewing all articles
Browse latest Browse all 13965