How can I use C++14 features when building qmake projects?

后端 未结 4 1772
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 18:16

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.

To enable C++11 in a Qt appli

4条回答
  •  悲哀的现实
    2020-12-01 18:40

    To use C++14 with qmake with versions before Qt 5.4 (it doesn't make any difference wether you use it with Qt Creator or with some other IDE or from command line) and gcc, add this to your .pro file:

    QMAKE_CXXFLAGS += -std=c++1y
    

    qmake got support for CONFIG += c++14 with Qt 5.4, so you can use that for projects where you are comfortable with requiring at least that version of Qt. Be sure to either use the explicit compiler flags, or use the CONFIG option, but not both at the same time, to avoid conflicting switches.


    Unfortunately gcc 4.8.2 supports very few C++14 features (see here), but you can test that with this code snippet:

    #include 
    
    auto f() { return 42; }
    
    int main()
    {
        std::cout << f() << std::endl;
    }
    

    That will compile fine with QMAKE_CXXFLAGS += -std=c++1y, but give warning with CONFIG += c++11 or QMAKE_CXXFLAGS += -std=c++1x.

提交回复
热议问题