Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-29481

QSqlDatabase documentation unclear about reference counting and closing() of connections.

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P3: Somewhat important
    • 5.0.2
    • 5.0.0
    • SQL Support
    • None
    • 0b8065b5819efd8ba3741ea5703d5b95954b16c2

    Description

      The documentation of the QSqlDatabase destructor states:

      "Destroys the object and frees any allocated resources.

      If this is the last QSqlDatabase object that uses a certain database connection, the database connection is automatically closed."

      This lead me to the impression that if I aquire a QSqlDatabase object by the static ::database() call (or by ::addDatabase()) and the object subsequently goes out of scope the connection would be closed. See the attached zip file for an example. All aquired QSqlDatabase objects are stack local and go out of scope. Contrary to my expectations the connection is not closed and reopened though.

      After rereading the documentation of the ::addDatabase() call it slowly dawned on me that there is another QSqlDatabase object stored implicitly. This is made somewhat implicit by the wording of the documentation. Here the term "database connection" is used, while in the destructor docs the term "QSqlDatabase object" is used.

      The documentation could be updated to clarify this. I would be willing to contribute a documentation patch if it is agreed upon that this is a real issue.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mabrand Mark Brand
            tapas Florian Paul Schmidt
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes