unique_ptr in Qt project

≡放荡痞女 提交于 2020-01-03 08:55:07

问题


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!


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/30031472/unique-ptr-in-qt-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!