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



  • 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


  • Moderators

    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)?



  • 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?


  • Moderators

    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.



  • 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.



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


  • Moderators

    @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.



  • @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 ;)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.