Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. The Lounge
  4. Qt smart pointers vs STL smart pointers
Forum Updated to NodeBB v4.3 + New Features

Qt smart pointers vs STL smart pointers

Scheduled Pinned Locked Moved Unsolved The Lounge
5 Posts 3 Posters 3.8k Views 2 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.
  • A Offline
    A Offline
    aliks-os
    wrote on 1 Mar 2017, 13:27 last edited by
    #1

    I just have started to use smart pointers in my applications and a little bit confused: what type of smart pointers better to use in developing Qt or STL ?

    During the last period, some elements of Qt are marked as obsolete and recomended to use its stl analoge, for example:
    foreach -> for range
    qSort -> std::sort (Members for QtAlgorithms).

    Is a possible situation when someday the Qt smart pointers will announced as obsolete ? And will be recomendation to use stl smart pointers...:)

    K 1 Reply Last reply 1 Mar 2017, 14:30
    1
    • A aliks-os
      1 Mar 2017, 13:27

      I just have started to use smart pointers in my applications and a little bit confused: what type of smart pointers better to use in developing Qt or STL ?

      During the last period, some elements of Qt are marked as obsolete and recomended to use its stl analoge, for example:
      foreach -> for range
      qSort -> std::sort (Members for QtAlgorithms).

      Is a possible situation when someday the Qt smart pointers will announced as obsolete ? And will be recomendation to use stl smart pointers...:)

      K Offline
      K Offline
      koahnig
      wrote on 1 Mar 2017, 14:30 last edited by
      #2

      @aliks-os

      Nothing is chisled in stone and may change epecially i the world of software.

      In my opinion the first shall be with what you fill more comfortable?
      That should probably have the highest priority for you.

      For myself I am not using pure Qt. It is in most cases a mix of the worlds of Qt, stl and boost. For the latter one my rational is that it will become stl and therefore there should be no problem. This I cannot underline anymore, since shared_ptr became part of stl. At least my rational at the moment that they will work the same way, I do not dare to change them swiftly from boost to stl.

      Personally I am continuing to use containers and string from stl. This makes it a bit awkward when working with Qt gui and you end end up with some mix.

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

      A 1 Reply Last reply 1 Mar 2017, 14:39
      0
      • K koahnig
        1 Mar 2017, 14:30

        @aliks-os

        Nothing is chisled in stone and may change epecially i the world of software.

        In my opinion the first shall be with what you fill more comfortable?
        That should probably have the highest priority for you.

        For myself I am not using pure Qt. It is in most cases a mix of the worlds of Qt, stl and boost. For the latter one my rational is that it will become stl and therefore there should be no problem. This I cannot underline anymore, since shared_ptr became part of stl. At least my rational at the moment that they will work the same way, I do not dare to change them swiftly from boost to stl.

        Personally I am continuing to use containers and string from stl. This makes it a bit awkward when working with Qt gui and you end end up with some mix.

        A Offline
        A Offline
        aliks-os
        wrote on 1 Mar 2017, 14:39 last edited by
        #3

        @koahnig
        Many thanks for your opinion.

        I read some debate on this subject, and some expressed that "if you started using Qt in the project, you should use Qt containers, smart pointers, etc as much as possible in the project. And better not mix Qt and STL"

        and I would like to know about this experience with the use of more experienced professionals than I

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 1 Mar 2017, 20:04 last edited by kshegunov 3 Jan 2017, 20:05
          #4

          It would very much depend on what you want to do. I, for one, stick to Qt's QSharedDataPointer and QExplicitlySharedDataPointer. Aside from those two I rarely touch any other smart pointer machinery. I dislike the STL API so even if I decide I need something more exotic I stick to Qt's implementations. Probably the notable exception is QPointer which has no STL equivalent to begin with, as it provides a guarded pointer to QObject instances, which is Qt specific. There's nothing wrong in mixing STL containers in, but some Qt concepts and parts of the API predates the STL's implementations, so they can be a pain to manage together, especially in threaded environments.

          Read and abide by the Qt Code of Conduct

          A 1 Reply Last reply 2 Mar 2017, 10:36
          0
          • K kshegunov
            1 Mar 2017, 20:04

            It would very much depend on what you want to do. I, for one, stick to Qt's QSharedDataPointer and QExplicitlySharedDataPointer. Aside from those two I rarely touch any other smart pointer machinery. I dislike the STL API so even if I decide I need something more exotic I stick to Qt's implementations. Probably the notable exception is QPointer which has no STL equivalent to begin with, as it provides a guarded pointer to QObject instances, which is Qt specific. There's nothing wrong in mixing STL containers in, but some Qt concepts and parts of the API predates the STL's implementations, so they can be a pain to manage together, especially in threaded environments.

            A Offline
            A Offline
            aliks-os
            wrote on 2 Mar 2017, 10:36 last edited by
            #5

            @kshegunov
            Thank you, noted. As I see from various source code, nobody follow to some rule, and everyone writes it as he like.

            1 Reply Last reply
            0

            1/5

            1 Mar 2017, 13:27

            • Login

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