Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    Tools
    3
    8
    5435
    Loading More Posts
    • 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
      moravas last edited by 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

      rd03 1 Reply Last reply Reply Quote 1
      • Chris Kawa
        Chris Kawa Moderators last edited by Chris Kawa

        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 Reply Quote 0
        • M
          moravas last edited by moravas

          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 Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by Chris Kawa

            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 Reply Quote 0
            • M
              moravas last edited by

              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 Reply Quote 0
              • rd03
                rd03 @moravas last edited by

                @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 Reply Quote 0
                • Chris Kawa
                  Chris Kawa Moderators last edited by 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.

                  rd03 1 Reply Last reply Reply Quote 0
                  • rd03
                    rd03 @Chris Kawa last edited by

                    @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 Reply Quote 0
                    • First post
                      Last post