Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions
[SOLVED][Moved] Where are std::shared_ptr and std::unique_ptr
[EDIT: moved to the C++ forum, this is nothing special to Qt, Volker]
I see the recent release of the SDK has support for plenty of the c++11 features, but when I try to use standard shared and unique smart pointers, Qt Creator says:
error: 'unique_ptr' is not a member of 'std'@
Do I need to do something extra to enable smart pointers or they are just not there?
In VS2010 smart pointers work fine and dandy along with Qt.
Did you ...
@ and did you enable the C++11 language features for MinGW using ... ? @
QMAKE_CXXFLAGS += -std=gnu++0x
Notice that it is gnu++0x, not c++0x, which causes some serious compilation errors with MinGW 4.4. C++11 support in 4.4 is mediocre, so expect to run into problems (compiler segfaults and alike). If you want to use C++11 features with MinGW I strongly advise to update ot a recent version.
10x, there is "somewhat of a progress"
Now I get:
@cc1plus.exe:-1: error: error: unrecognized command line option "-std=gnuc++0x"@
It's gnu++0x, not gnuc++0x.
Ah, thanks, it is all working fine and dandy now
BTW I notice unlike plain pointers, Qt Creator does not recognize smart pointer instances as pointers and does not automatically use -> instead of .
No "intellisense" for the object pointed to methods either, i guess for now c++11 features are "in the blind" for Qt Creator
Well, I think that's because smart pointers are first off objects, not pointers (altough they incorporate a pointer). So Qt Creators code completion just works fine here - but it would be indeed a nice feature that some classes can be marked as "pointer classes" which cause Qt Creator to prefer -> over .
If the problem has been solved for you feel free to prepend the title of your inital post with [Solved] to indicate that there is an solution inside.
Yep, the . syntax should get the methods for the actual smart pointer object whereas the -> refers to the object pointed to by the smart pointer. Actually It will be a bad thing if Creator is tuned to automatically convert . to -> for smart pointers, which would make it hard to access the actual pointer member functions, plain C pointers do not have member functions but smart pointers do, the operators for smart pointers have been overloaded to work as plain C pointers but smart pointers are classes.
But even without automatic . to -> it would be a good thing for Creator to list the members of the object pointed to using ->, since the current version doesn't seem to be able to get to the pointed to object and list members.
std::unique_ptr<MyClass> uPtr1(new MyClass());
qDebug() << uPtr1->text();
qDebug() << (*uPtr1).text();@
None of the those two methods gets any code completion for MyClass methods
Saul last edited by
Autocomplete works through std::shared_ptr if I add
@DEFINES += GXX_EXPERIMENTAL_CXX0X@
to my .pro file.
I am using the latest build (2.6.0-rc), but this may still work for older builds?
saedelaere last edited by
Autocomplete in 2.6.0 works for me with std::shared_ptr even without the DEFINES Paul postet. But it seems like std::unique_ptr is not supported yet :/