Nominate our 2022 Qt Champions!

How do I compile my project using C++17?

  • Hi I want to use some new features of C++17 for my project so I want to add it in the project file. But I don't know where to declare it.

    My project file starts something like this

    CONFIG += qt
    QT += widgets
    QT += network
    QT_VERSION_WARNING = "WARNING: Linking against Qt version lower than 5.6.1 is likely to cause CLI tools video encoding to crash due to I/O but in Qt."

    And then somewhere in the file it has another line mentioning about CONFIG += C++

    contains(QMAKE_COMPILER, gcc) {
    	QMAKE_CXXFLAGS += -std=c++11
    	QMAKE_CXXFLAGS += -Wall
    	QMAKE_CXXFLAGS += -Wextra
    	QMAKE_CXXFLAGS += -Wredundant-decls
    	QMAKE_CXXFLAGS += -Wshadow
    	#QMAKE_CXXFLAGS += -Weffc++
    	QMAKE_CXXFLAGS += -pedantic
    } else {
            CONFIG += c++11

    Where do I need to update it?

  • Lifetime Qt Champion


    You should add CONFIG += c++17 to your .pro file for C++ 17. If you want the support for the latest standard supported by your compiler use "c++latest".

  • @SGaist

    Where do I add it? After the first line or change the one in that else statement?

  • Lifetime Qt Champion

    If you want to use it unconditionally, you should remove the mentions of C++11 completely and put the CONFiG line before the other changes.

  • @SGaist

    This line also? And change it to c++17?
    QMAKE_CXXFLAGS += -std=c++11

  • Lifetime Qt Champion

    You should check why the gcc flags where modified that way and then see if the c++17 switch from CONFIG fills them in a compatible way. Otherwise, yes you have to replace it.

Log in to reply