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. QSharedPointer vs std::shared_ptr
Forum Updated to NodeBB v4.3 + New Features

QSharedPointer vs std::shared_ptr

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 2.2k 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.
  • T Offline
    T Offline
    tonka
    wrote on last edited by
    #1

    Hey,

    since C++ 11 we can choose (in a Qt dev environment) between QSharedPointer and std::shared_ptr. Can anybody tell me if i should prefer std::shared_ptr or QSharedPointer and why - if i create a new class.

    Here is what i know now:

    • QSharedPointer can be used in a non C++ 11 compiler (pro QSharedPointer)
    • std::shared_ptr is moveable, QSharedPointer not (pro std::shared_ptr)
    • std::shared_ptr reference is boost::shared_ptr (pro std::shared_ptr)

    Thanks in advance
    Tonka

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      It mostly depends on your needs. QSharedPointer is obviously better with Qt types, as it provides convenience functions like qSharedPointerObjectCast.

      It's also older than shared_ptr so it doesn't have move semantics treatment, but the benefits of moving a shared pointer are minor IMHO. I guess it's possible that it would get an update in Qt6.

      In most cases it's a preference choice. I used both intensively in the past and have never met a scenario when one would fit better than the other, except for the mentioned casting benefits.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        tonka
        wrote on last edited by
        #3

        thx for the answer. I will prefer QSharedPointer over std::shared_ptr

        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