Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unique_ptr in Qt project

Tags:

c++

unique-ptr

qt

I have a simple Qt project. I include <memory> but std::unique_ptr is not available. I know that I should use Qt specific smart pointers but I need to include a larger project that contains std::unique_ptr.

What can I do?

Thanks!

like image 253
yonutix Avatar asked May 04 '15 13:05

yonutix


2 Answers

C++11 is required for smart pointers. Depending on your version of Qt:

Add CONFIG += c++11 to your .pro file if you have Qt5 and above. It needs to include <memory> as Simon mentioned.

If you have an earlier version than Qt5, try adding this:
QMAKE_CXXFLAGS += -std=c++11

like image 79
Andreas DM Avatar answered Nov 15 '22 15:11

Andreas DM


Include memory:

#include <memory>

Configure your Qt project to use C++11. Add to your .pro file:

CONFIG += c++11

If that does not solve the problem, please add a detailed error message.

like image 39
Simon Warta Avatar answered Nov 15 '22 16:11

Simon Warta