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. when using the qxorm to connect the sqlite ....
Forum Updated to NodeBB v4.3 + New Features

when using the qxorm to connect the sqlite ....

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 466 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.
  • nicker playerN Offline
    nicker playerN Offline
    nicker player
    wrote on last edited by
    #1

    m_DatabaseCurrent = qx::QxSqlDatabase::getSingleton()->getDatabaseCloned();

    qx::QxSqlDatabase::getSingleton()->clearAllSettingsForCurrentThread();
    //m_DatabaseCurrent.close();
    if(QSqlDatabase::database(m_DatabaseCurrent.connectionName()).isOpen()){
    QSqlDatabase::database(m_DatabaseCurrent.connectionName()).close();
    }
    if(QSqlDatabase::contains(m_DatabaseCurrent.connectionName())){
    QSqlDatabase::removeDatabase(m_DatabaseCurrent.connectionName());
    }

    the output tips:
    QSqlDatabasePrivate::removeDatabase: connection '{4988436d-8dbb-4670-a7f4-f4fb11f8136f}' is still in use, all queries will cease to work.

    i just tried to close the database and removed the connection .but it failed.i dont know what should i do to solve this problem.

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

      Hi,

      Don't store QSqlDatabase objects as a member variable.
      It's shown in the class documentation.

      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
      1
      • nicker playerN Offline
        nicker playerN Offline
        nicker player
        wrote on last edited by
        #3

        so how to get the pointer of the database that Ive connected?
        the method that Database() came out the instance of the database,but not the pointer of the instance connected.Am i right?

        JonBJ 1 Reply Last reply
        0
        • nicker playerN nicker player

          so how to get the pointer of the database that Ive connected?
          the method that Database() came out the instance of the database,but not the pointer of the instance connected.Am i right?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @nicker-player
          Did you read the documentation where it has a "red, warning box" stating

          Warning: It is highly recommended that you do not keep a copy of the QSqlDatabase around as a member of a class, as this will prevent the instance from being correctly cleaned up on shutdown. If you need to access an existing QSqlDatabase, it should be accessed with database(). If you chose to have a QSqlDatabase member variable, this needs to be deleted before the QCoreApplication instance is deleted, otherwise it may lead to undefined behavior.

          ? So don't use m_DatabaseCurrent = qx::QxSqlDatabase::getSingleton()->getDatabaseCloned(); where m_DatabaseCurrent is a class member variable, use QSqlDatabase db = QSqlDatabase::database(); if you want a local variable or just QSqlDatabase::database() directly.

          1 Reply Last reply
          2
          • nicker playerN Offline
            nicker playerN Offline
            nicker player
            wrote on last edited by
            #5

            but the way u just mentioned could not get what I want.
            the qxorm need to use the qsqldatebase pointer from the intance.how can I get the real pointer from the method of QSqlDatabase::database()

            jsulmJ SGaistS 2 Replies Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Simply do it like @JonB told you... don't store it as member, don't have an active insance around (which also means no local db instance) when removing the database connection.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • nicker playerN nicker player

                but the way u just mentioned could not get what I want.
                the qxorm need to use the qsqldatebase pointer from the intance.how can I get the real pointer from the method of QSqlDatabase::database()

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @nicker-player said in when using the qxorm to connect the sqlite ....:

                how can I get the real pointer from the method of QSqlDatabase::database()

                Do you know how you get the pointer to an object in C++? This is basic C++.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • nicker playerN nicker player

                  but the way u just mentioned could not get what I want.
                  the qxorm need to use the qsqldatebase pointer from the intance.how can I get the real pointer from the method of QSqlDatabase::database()

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @nicker-player said in when using the qxorm to connect the sqlite ....:

                  but the way u just mentioned could not get what I want.
                  the qxorm need to use the qsqldatebase pointer from the intance.how can I get the real pointer from the method of QSqlDatabase::database()

                  Beside the question of @jsulm, which method needing a pointer are you trying to call ?

                  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