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. do i have to delete query object pointer?
QtWS25 Last Chance

do i have to delete query object pointer?

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 2 Posters 1.2k 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    when i create a QSqlQuery in the heap with database, do i need to delete the object later, or the database takes care of that?
    m_pQuery = new QSqlQuery(QSqlDatabase::database());

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

      Hi,

      Yes, you have to.

      However, if you re-read the API making use of QSqlQuery, you'll see none of them uses objects allocated in the heap.

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

      U 1 Reply Last reply
      3
      • SGaistS SGaist

        Hi,

        Yes, you have to.

        However, if you re-read the API making use of QSqlQuery, you'll see none of them uses objects allocated in the heap.

        U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        @sgaist
        okay, in that case i guess i'll store just a member object.

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

          Why do you need to store that query as member variable ?

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

          U 1 Reply Last reply
          0
          • SGaistS SGaist

            Why do you need to store that query as member variable ?

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #5

            @sgaist
            well i'm creating and executing the query in a data source class (for table view), then each colomn takes the query from the data source and gets appropriate value from it.

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

              Then you should rather keep the string of the query and build the QSqlQuery object when you actually need it.

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

              U 1 Reply Last reply
              1
              • SGaistS SGaist

                Then you should rather keep the string of the query and build the QSqlQuery object when you actually need it.

                U Offline
                U Offline
                user4592357
                wrote on last edited by
                #7

                @sgaist
                then how will the columns get the results?

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

                  Can you share the code you are using ?
                  It looks like you could make use of a QSqlQueryModel.

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

                  U 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Can you share the code you are using ?
                    It looks like you could make use of a QSqlQueryModel.

                    U Offline
                    U Offline
                    user4592357
                    wrote on last edited by user4592357
                    #9

                    @sgaist
                    no i'm on mobile now, and soon to sleep. will take a look at it tomorrow and see if i can use it. thanks

                    U 1 Reply Last reply
                    0
                    • U user4592357

                      @sgaist
                      no i'm on mobile now, and soon to sleep. will take a look at it tomorrow and see if i can use it. thanks

                      U Offline
                      U Offline
                      user4592357
                      wrote on last edited by
                      #10

                      @SGaist
                      i took a look at QSqlQueryModel but i guess i can't use it because my table view already has a model.

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

                        What kind ?

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

                        U 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          What kind ?

                          U Offline
                          U Offline
                          user4592357
                          wrote on last edited by
                          #12

                          @sgaist
                          it is QAbstractTableModel

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

                            You can replace your model unless you are doing something special with it ?

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

                            U 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              You can replace your model unless you are doing something special with it ?

                              U Offline
                              U Offline
                              user4592357
                              wrote on last edited by
                              #14

                              @sgaist
                              that's the thing. i can't replace it cause it's doing a lot of things (it's part of a library someone has created and I'm using it)

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

                                How are you using it since you need to query a database ?

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

                                U 1 Reply Last reply
                                0
                                • SGaistS SGaist

                                  How are you using it since you need to query a database ?

                                  U Offline
                                  U Offline
                                  user4592357
                                  wrote on last edited by
                                  #16

                                  @sgaist
                                  it has some long logic built into it, it sets up a lot of connections etc.

                                  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