Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt Creator doesn't handle std::unique_ptr and shared_ptr as expected
QtWS25 Last Chance

Qt Creator doesn't handle std::unique_ptr and shared_ptr as expected

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
8 Posts 3 Posters 6.4k 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.
  • M Offline
    M Offline
    moravas
    wrote on last edited by moravas
    #1

    Hi Folks,

    our project heavily uses C++11 std::shared and std::unique ptr. During the code editing we faced that the Qt's editor doesn't offer code completion on the pointers type above.
    While defining QSharedPointer<SomeType> SomeTypePtr results that Qt offer methods in SomeType by typing SomeTypePtr->, this isn't the case is we are doing with std pointers.
    Can anybody help me how can we solve this issue? Can we have a bugfix in the near future?

    Regards,
    Norbert

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

      It works correctly for me in Qt Creator 3.6.1. It suggests methods of the shared_ptr when I type . and the ones of embedded type when I type ->.

      Do you have #include "<memory>" which the std pointers reside in?
      Which Qt Creator version are you using?
      Also, are you using the built-in code model or the Clang based one (Tools->Options->C++->Code Model)?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        moravas
        wrote on last edited by moravas
        #3

        Hi,

        I use Qt Creator 3.6.1 too on Ubuntu 14.04 with GCC 4.8.4 with the build in code model. Do you suggest to use Clang?
        The project is improted from an existing project so maybe there is no directly included <memory> header.
        Is there any way to "preinclude" this by avoiding the source modification?

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

          It has to be included somewhere, either directly or in one of the included files, otherwise it's relying on implementation specific standard library behavior.
          Do you use precompiled headers? It would be a good place for it.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            moravas
            wrote on last edited by
            #5

            I included the <memory> header explicitly, and it worked for shared pointers after waiting some time (maybe the size of the project was the reason), but it's not the case of unique_ptr.
            I checked that we are using gcc-4.8.4 and as I have been seen in the gcc release note, it already supports unique_ptr.

            1 Reply Last reply
            0
            • M moravas

              Hi Folks,

              our project heavily uses C++11 std::shared and std::unique ptr. During the code editing we faced that the Qt's editor doesn't offer code completion on the pointers type above.
              While defining QSharedPointer<SomeType> SomeTypePtr results that Qt offer methods in SomeType by typing SomeTypePtr->, this isn't the case is we are doing with std pointers.
              Can anybody help me how can we solve this issue? Can we have a bugfix in the near future?

              Regards,
              Norbert

              rd03R Offline
              rd03R Offline
              rd03
              wrote on last edited by
              #6

              @moravas This finally bothered me enough I created a bug report for this behavior. https://bugreports.qt.io/browse/QTCREATORBUG-16091

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

                @rd03 shared_ptr and unique_ptr autocompletion works with Clang code model enabled (see my first response). The weak_ptr example from your report makes no sense so it won't have any autocomplete. You can't create a weak_ptr from raw pointer and there are no overloaded operators * or -> in weak_ptr.

                @moravas

                I checked that we are using gcc-4.8.4 and as I have been seen in the gcc release note, it already supports unique_ptr

                Make sure you put CONFIG += c++11 in the .pro file and re-run qmake to enable c++11 support in gcc. It's using the older standard by default.

                rd03R 1 Reply Last reply
                0
                • Chris KawaC Chris Kawa

                  @rd03 shared_ptr and unique_ptr autocompletion works with Clang code model enabled (see my first response). The weak_ptr example from your report makes no sense so it won't have any autocomplete. You can't create a weak_ptr from raw pointer and there are no overloaded operators * or -> in weak_ptr.

                  @moravas

                  I checked that we are using gcc-4.8.4 and as I have been seen in the gcc release note, it already supports unique_ptr

                  Make sure you put CONFIG += c++11 in the .pro file and re-run qmake to enable c++11 support in gcc. It's using the older standard by default.

                  rd03R Offline
                  rd03R Offline
                  rd03
                  wrote on last edited by
                  #8

                  @Chris-Kawa You are correct that the weak_ptr doesn't make sense, oops! Unfortunately the clang code model is still too slow for most projects that I work on, updates take for-freaking-ever. If the devs want to push everything to the clang model and deprecate the built in, that's fine as long as they work out the speed issues. Until that happens the lesser of the two evils is no autocomplete with smart pointers ;)

                  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