Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlDatabase common problem
Forum Updated to NodeBB v4.3 + New Features

QSqlDatabase common problem

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 6.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xeroblast
    wrote on last edited by
    #1

    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...

    @
    window::window()
    {
    {
    db = QSqlDatabase::addDatabase("QMYSQL");
    // query here
    query.clear();
    db.close();
    }
    QSqlDatabase.removeDatabase("QMYSQL");
    }
    @

    1 Reply Last reply
    0
    • I Offline
      I Offline
      Immii
      wrote on last edited by
      #2

      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");

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Immii
        wrote on last edited by
        #3

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

        QSqlDatabase db = QSqlDatabase::database("your connection name");

        1 Reply Last reply
        0
        • I Offline
          I Offline
          Immii
          wrote on last edited by
          #4

          i just found this "thread":http://developer.qt.nokia.com/forums/viewthread/328/

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xeroblast
            wrote on last edited by
            #5

            it is close running a db.isOpen()...

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xeroblast
              wrote on last edited by
              #6

              i limit the error by doing something like this

              @
              window::window() {
              QString conn = db.connectionName();
              if (conn.isEmpty()) {
              db = QSqlDatabase::addDatabase("QMYSQL");
              }
              }
              window::close() {
              QSqlDatabase::removeDatabase("QMYSQL");
              }
              @

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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                [quote author="xeroblast" date="1293007954"]but this is not enough coz tha last query still displays the error coz the dbase is not remove...[/quote]

                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.

                1 Reply Last reply
                0
                • X Offline
                  X Offline
                  xeroblast
                  wrote on last edited by
                  #8

                  im sorry...

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved