問題描述
我目前在我的 Qt 應用程序中使用 C++11 功能.但是,我想在我的應用程序中使用一些新的 C++14 特性.
I'm currently using C++11 features in my Qt applications. However, I'd like to use some of the new C++14 features in my applications.
要在Qt應用程序中啟用C++11,只需在qmake項目文件中添加一行,即:
To enable C++11 in a Qt application, one only needs to add one line in the qmake project file, namely:
CONFIG += c++11
或者對于早期版本:
QMAKE_CXXFLAGS += -std=c++1y
我已經嘗試用 C++14 做同樣的事情,但是沒有用.我像這樣更改了 qmake 項目的上述行:
I already tried to do the same with C++14, but it didn't work. I changed the above mentioned line of the qmake project like this:
CONFIG += c++14
或者對于早期版本:
QMAKE_CXXFLAGS += -std=c++1y
之后,在嘗試構建項目時出現了許多以前不存在的編譯錯誤.該項目編譯正常,但是,如果我嘗試使用任何 C++14 功能,則會出現編譯錯誤.這是一個例子:
After that, lots of compilation errors, that did not exist before, appear when trying to build the project. The project compiles fine, however, if I try to use any C++14 features, I get a compilation error. This is an example:
template<typename T>
constexpr T pi = T(3.1415926535897932385);
這是相應的錯誤:
main.cpp:7: error: template declaration of 'constexpr const T pi'
constexpr T pi = T(3.1415926535897932385);
^
在 QtCreator 中使用 qmake 項目時如何啟用 C++14 功能?
How to enable C++14 features when using a qmake project in QtCreator?
我使用的是 Qt 5.3.2、Qt Creator 3.2.1 和 MinGW 4.8.2 32 位.
I am using Qt 5.3.2, Qt Creator 3.2.1, and MinGW 4.8.2 32 bit.
推薦答案
Qt Creator 只是一個 IDE.
您可以將 IDE 視為更智能文本編輯器",幫助開發人員進行調試、構建、代碼完成、文件管理等.
You can think of IDEs as "smarter text editors" that aid the developer with debugging, building, code completion, file management and so on.
IDE 在編譯過程中無關緊要.
IDEs are irrelevant during compilation.
重要的是您的編譯器.它獨立于您的 IDE.
g++ 4.8.x 不支持許多 C++14 功能:查看此頁面以了解支持哪些 C++14 功能.
g++ 4.8.x does not support many C++14 features: check out this page to learn what C++14 features are supported.
這篇關于構建 qmake 項目時如何使用 C++14 功能?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!