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. Why Qt does not use smart pointers?
Qt 6.11 is out! See what's new in the release blog

Why Qt does not use smart pointers?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 6.0k 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.
  • S Offline
    S Offline
    Skyrpex
    wrote on last edited by
    #1

    Does anyone know why does Qt not use smart pointers at all? For example, QObject could use shared pointers to store children and weak pointers to reference its parent.

    Thanks,

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Well, Qt does use smart pointers such as "QScopedPointer":http://qt-project.org/doc/qt-5.0/qtcore/qscopedpointer.html
      "QSharedPointer":http://qt-project.org/doc/qt-5.0/qtcore/qsharedpointer.html and "QWeakPointer":http://qt-project.org/doc/qt-5.0/qtcore/qweakpointer.html

      [edit, typing errors corrected, koahnig]

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Skyrpex
        wrote on last edited by
        #3

        I know those classes, but Qt itself doesn't really use it AFAIK. For instance, QObject for parent/children, QListWidgetItem, etc, don't use smart pointers.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          OK, sorry, I understood your question differently.
          There has been a similar discussion lately here on devnet, but i do not know how to find.
          For sure I cannot answer this question satisfactorily. AFAIK the overall design concept is different. That has been good enough for me so far :)

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            do you actually miss it?
            I think it works well without them also. And using smart pointers for all pointers would also come with extra cost of operating penalty.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tilsitt
              wrote on last edited by
              #6

              Hi,

              Why Qt doesn't use smart pointers? Because it doesn't need to. Smart pointers are useful for shared objects, or to ensure destruction. Because a QObject (or an item in a view) can have only one parent, there is no sharing. For the same reason, the destruction can be done by the parent without using "complex" tools like smart pointers.

              Just by curiosity, why are you asking?

              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