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 with MYSQL management in the app
QtWS25 Last Chance

QSqlDatabase with MYSQL management in the app

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 4 Posters 4.5k Views
  • 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.
  • SGaistS SGaist

    Please show the complete code you are currently using.

    You should also check if you have other QSqlDatabase objects lying around.

    Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by Cobra91151
    #21

    @SGaist

    I don't have any member variable, only local variable QSqlDatabase db = QSqlDatabase::database("TestConnection"); to get the DB connection and use it to execute queries. It should deletes itself when it goes out of scope. So I think no QSqlDatabase objects are lying around.

    More info available - warning remove database

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #22

      The correct way is described in the documentation of the function:

      void someFunction()
      {
          {
              QSqlDatabase db = QSqlDatabase::database("sales");
              QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db);
          }
          // Both "db" and "query" are destroyed because they are out of scope 
          QSqlDatabase::removeDatabase("sales"); // correct
      }
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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