Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved do i have to delete query object pointer?

    General and Desktop
    2
    16
    414
    Loading More Posts
    • 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
      user4592357 last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 3
        • U
          user4592357 @SGaist last edited by

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

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • U
              user4592357 @SGaist last edited by

              @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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 1
                • U
                  user4592357 @SGaist last edited by

                  @sgaist
                  then how will the columns get the results?

                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    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 Reply Quote 0
                    • U
                      user4592357 @SGaist last edited by 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 1 Reply Last reply Reply Quote 0
                      • U
                        user4592357 @user4592357 last edited by

                        @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 Reply Quote 0
                        • SGaist
                          SGaist Lifetime Qt Champion last edited by

                          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 Reply Quote 0
                          • U
                            user4592357 @SGaist last edited by

                            @sgaist
                            it is QAbstractTableModel

                            1 Reply Last reply Reply Quote 0
                            • SGaist
                              SGaist Lifetime Qt Champion last edited by

                              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 Reply Quote 0
                              • U
                                user4592357 @SGaist last edited by

                                @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 Reply Quote 0
                                • SGaist
                                  SGaist Lifetime Qt Champion last edited by

                                  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 Reply Quote 0
                                  • U
                                    user4592357 @SGaist last edited by

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

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post