December 22, 2010

xeroblast xeroblast
Lab Rat
91 posts

QSqlDatabase common problem

 

why do i get this error : QSqlDatabasePrivate::addDatabase: duplicate connection name ‘qt_sql_default_connection’, old connection removed.

i already follow what’s in the docs…

  1. window::window()
  2. {
  3.   {
  4.     db = QSqlDatabase::addDatabase("QMYSQL");
  5.     // query here
  6.     query.clear();
  7.     db.close();
  8.   }
  9.   QSqlDatabase.removeDatabase("QMYSQL");
  10. }

7 replies

December 22, 2010

Immii Immii
Ant Farmer
233 posts

http://doc.trolltech.com/4.2/qsqldatabase.html#addDatabase

can you check with this if DB is still open?
bool db.isOpen()
QDatabase::removeDatabase(“databaseName”);

December 22, 2010

Immii Immii
Ant Farmer
233 posts

u can try try using connection name when you add your DB and see

QSqlDatabase db = QSqlDatabase::database(“your connection name”);

December 22, 2010

Immii Immii
Ant Farmer
233 posts

i just found this thread [developer.qt.nokia.com]

December 22, 2010

xeroblast xeroblast
Lab Rat
91 posts

it is close running a db.isOpen()…

December 22, 2010

xeroblast xeroblast
Lab Rat
91 posts

i limit the error by doing something like this

  1. window::window() {
  2.   QString conn = db.connectionName();
  3.   if (conn.isEmpty()) {
  4.     db = QSqlDatabase::addDatabase("QMYSQL");
  5.   }
  6. }
  7. window::close() {
  8.   QSqlDatabase::removeDatabase("QMYSQL");
  9. }

but this is not enough coz tha last query still displays the error coz the dbase is not remove…

December 22, 2010

Andre Andre
Area 51 Engineer
6031 posts
xeroblast wrote:
but this is not enough coz tha last query still displays the error coz the dbase is not remove…

Off topic: could you try to write normal English please? “coz” “tha” etc. do not qualify. That would make your comments much easier to read. Thank you.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

December 22, 2010

xeroblast xeroblast
Lab Rat
91 posts

im sorry…

 
  ‹‹ Implementing SSHv2 in Qt      Phonon Deployment on Windows XP: No Video. ››

You must log in to post a reply. Not a member yet? Register here!