Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved compile c++11 file in qtcreator? problem with g++

    General and Desktop
    5
    15
    5337
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Q
      qtpi last edited by

      hey folks. the problem is as described in title. I added the CONFIG += C++11 in the .pro file. and it still cannot compile the file with c++11.
      I am not sure if there is problem with gcc cause when I checked the qmake command in the project option, it shows: qmake xxx.pro -r -spec linux-g++
      and my gcc is 4.9.2 so I think it is new enough to recognize c++11.
      my qt version is 5.3.2.

      what could be the problem?
      Thanks in advance!

      ? micland 2 Replies Last reply Reply Quote 0
      • ?
        A Former User @qtpi last edited by

        @qtpi Hi! What error does the compiler throw?

        Q 1 Reply Last reply Reply Quote 0
        • Q
          qtpi @Guest last edited by

          @Wieland hey. it says range-based 'for' loops are not allowed in c++98 mode.

          I am very confused. how come is it c++98?

          1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion last edited by

            hi
            can you try with
            QMAKE_CXXFLAGS += -std=c++11

            Q 1 Reply Last reply Reply Quote 0
            • micland
              micland @qtpi last edited by

              @qtpi said:

              hey folks. the problem is as described in title. I added the CONFIG += C++11 in the .pro file. and it still cannot compile the file with c++11.

              I'm not sure if the config values are case sensitive but I always used CONFIG += c++11 (with a lower cased C) which worked for me... give it a try?

              Q 1 Reply Last reply Reply Quote 1
              • Q
                qtpi @mrjj last edited by

                @mrjj

                hi. actually both configurations are in my .pro file. still shows it's c++98 mode. -.-

                1 Reply Last reply Reply Quote 0
                • Q
                  qtpi @micland last edited by

                  @micland thanks for the help. actually I tried these 2 different cases already. seems still not working.

                  1 Reply Last reply Reply Quote 0
                  • ?
                    A Former User last edited by

                    Did you try to manually clean the project and run qmake again?

                    Q 2 Replies Last reply Reply Quote 0
                    • Q
                      qtpi @Guest last edited by

                      @Wieland that's a option. I will try to do it tmr.

                      M 1 Reply Last reply Reply Quote 0
                      • M
                        medyakovvit @qtpi last edited by

                        @qtpi
                        Another places to check:
                        Check that you use correct gcc. There are a few versions of gcc can be installed. For example, i have gcc-4.8, gcc-4.9 and gcc-5. You can choose version to use with simple "gcc"(without mentioning any version) through
                        update-alternatives.

                        Another option, if you use Qt Creator you can manually compiler in Options->Build&Run in Compilers tab. In Compiler path you can point to concrete version, for example /usr/bin/g++-5.

                        Also, you can check compiler version and c++ standart at runtime, with:

                        std::cout << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__ << std::endl;
                        std::cout << __cplusplus << std::endl;
                        

                        Here you can find values returned by __cplusplus macro

                        Q 1 Reply Last reply Reply Quote 2
                        • Q
                          qtpi @medyakovvit last edited by

                          @medyakovvit
                          hi. thanks for the help. the gcc is 4.9 and the macro __cplusplus shows 199711.

                          -.- this is rly weird.

                          M 1 Reply Last reply Reply Quote 0
                          • Q
                            qtpi @Guest last edited by

                            @Wieland I tried it and it still not working...-.-

                            1 Reply Last reply Reply Quote 0
                            • Q
                              qtpi last edited by qtpi

                              update: I just solved the problem. I have included my source .pro as a sub .pro file in another .pro file: mySoftware.pro and I only changed the setting in mySoftware.pro.

                              After I changed the setting in the source.pro, everything works.

                              1 Reply Last reply Reply Quote 0
                              • M
                                medyakovvit @qtpi last edited by

                                @qtpi
                                You tried to run this code:

                                std::cout << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__ << std::endl;
                                std::cout << __cplusplus << std::endl;
                                

                                or you just look at cpluplus value from prompt?

                                Q 1 Reply Last reply Reply Quote 0
                                • Q
                                  qtpi @medyakovvit last edited by

                                  @medyakovvit said:

                                  I dont have the macro GNUC_PATCHLEVEL . So i only tried to check GNU MINOR and cplusplus.
                                  but the problem is solved, it seems if the pro file is placed on each other. it might be sometimes problematic with this setting.

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post