Qt Creator autocomplete (intellisense) does not work for std :: vector elements

How can I do autocomplete in Qt Creator for std::vector ? Is it normal for it not to work?

For example, in a new new project, I create struct foo { int bar; }; struct foo { int bar; }; . If I create a QVector foo, intellisense / autocomplete works fine:

enter image description here

But for std::vector<foo> v2 nothing happens after I hit the point in v2[0].

I am in Qt Creator 3.3.0 using the Visual Studio compiler toolchain (so the STL comes from VS, not gcc if that matters).

Edit: I found a bug related to this (about iterators) - https://bugreports.qt.io/browse/QTCREATORBUG-1892 . I also reproduce this problem.

Edit 2: I tested using a special template class:

 struct bar { int b; }; template<class T> struct foo { T operator [](int a) { return T(); } }; 

And it works great:

enter image description here

+7
c ++ autocomplete stl qt-creator
source share
3 answers

According to my comments, this is simply not possible. You can file a bug report and hope that they are fixed. To better explain, this has something to do with the implementation of std :: vector:

 reference operator[](difference_type _Off) const { // subscript return (*(*this + _Off)); } 

In which the reference typedef'ed as Allocator::reference . Qt Creator seems to have problems following this first class. Compare this to QVector ...

 inline T &QVector<T>::operator[](int i) { Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::operator[]", "index out of range"); return data()[i]; } 

... which is defined directly in terms of T &, and you can understand why it works for him.

Update: look at the cppreference page on the vector , it seems that after C ++ 11 the link should be printed as simply value_type &. I tried building with CONFIG += c++11 , but it still doesn't work.

And another update: handled with a minimum test case code that doesn't work

 template<typename T> class foo{ public: typedef T value_type; typedef value_type& reference; T a; reference operator[](int){return a;} }; struct bar{int b;}; 
+5
source share

The clang code model is now available:

Go to Help-> About plugins ... β†’ enable ClangCodeModel

Reboot Qt Creator. Make sure it is activated; Tools -> C ++ -> Code Model

Voila code autocomplete for std: vector.

+2
source share

I was able to simplify the @Cassio sample code to reproduce the problem:

 struct T { int b; }; struct foo{ typedef T value_type; T a; value_type operator[](int); value_type bar(); }; 

Interestingly, a.bar(). works, but a[1]. not. Also, most importantly, if you declare the [] operator as foo::value_type operator[](int); autocomplete will work.

0
source share

All Articles