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. QT example sqlbrowser : clarification about variables scopes

QT example sqlbrowser : clarification about variables scopes

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 526 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.
  • T Offline
    T Offline
    Thombou
    wrote on 1 Nov 2020, 15:26 last edited by
    #1

    Hi all, I am reading the QT example sql_browser and one question pops up in my mind. This is also related to basic C++ I guess (scopes).

    In the void Browser::exec() function (browser.cpp, line 84), the model to the table view is changed to display the output of the query typed in the sqlEdit part. In this function, a new pointer is created to a QSqlQueryModel. Later in the execution, the model of the TableView can be changed.
    My question is what happen to the model pointer created in the exec function once the model associated to the table view is changed. As far as I understand, there is no reference anymore to that pointer, so it seems to be memory leak. Am I right?

    Then suppose the user is entering in the same function again. I would say then that a new pointer will be created for another QSqlQueryModel. Is it right or does it uses the same memory space as the previous execution of this function?

    Thank you for your help
    Kind regards
    Thombou

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 1 Nov 2020, 15:48 last edited by
      #2

      There is no leak since a parent is passed to QSqlQueryModel even though you're correct - a 'delete view->model()' before setting the new one would be better here.

      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
      4
      • T Offline
        T Offline
        Thombou
        wrote on 5 Nov 2020, 06:28 last edited by
        #3

        Ok thank you for the clarification :)

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 5 Nov 2020, 06:29 last edited by
          #4

          Then please mark this topic as solved, thx.

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

          T 1 Reply Last reply 5 Nov 2020, 06:39
          0
          • C Christian Ehrlicher
            5 Nov 2020, 06:29

            Then please mark this topic as solved, thx.

            T Offline
            T Offline
            Thombou
            wrote on 5 Nov 2020, 06:39 last edited by
            #5

            @Christian-Ehrlicher I put it as a general discussion thread as it it not really a problem. Is that ok?

            C 1 Reply Last reply 5 Nov 2020, 06:40
            0
            • T Thombou
              5 Nov 2020, 06:39

              @Christian-Ehrlicher I put it as a general discussion thread as it it not really a problem. Is that ok?

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 5 Nov 2020, 06:40 last edited by
              #6

              @Thombou Yes :)

              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
              0

              1/6

              1 Nov 2020, 15:26

              • Login

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