UPDATE (6/24/12): I’ve updated instruction on how to get Qt working also, Please use that article here, if you’d like full functionality.
I wanted to play with c++11 features while using Qt Creator as my IDE. Here are the steps:
1.) download “mingw32-gcc-4.6.2-release-c,c++,fortran-sjlj-FINAL.zip” from http://code.google.com/p/mingw-builds/downloads/list (They recommend the latest with the FINAL keyword at the end).
2.) Make a copy of C:\QtSDK\mingw just incase something didn’t go right or you have to revert to it in the future.
3.) Extract the zip to C:\QtSDK\mingw
4.) Launching the qt mingw command prompt and running g++ –version should now show the version you downloaded and extracted:
C:\>g++ --version g++ (niXman build) 4.6.2 Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5.) Compiled this test code below to see if c++11 features were working:
g++ -std=gnu++0x test.cpp && a.exe
#include <iostream> #include <vector> #include <memory> /* Delgating constructors isn't implemented in gcc 4.6! */ /* class Multiply { int m_var; int m_mult; public: Multiply(int var, int mult) { m_var = var; m_mult = mult; } Multiply(int mult) : Multiply(mult, mult) { } int calc() const { return m_var * m_mult; } }; */ struct Test { int a; int b; std::string c; }; void printTest(Test t) { std::cout << t.a << "\t" << t.b << "\t" << t.c << std::endl; } std::string* createNewString() { return new std::string(u8"Hello World! Unicode Character: \u2018"); } int main(int argc, char** argv) { std::vector<int> test = {1, 2, 3, 4, 5}; for (auto& x : test) std::cout << x << std::endl; printTest({test.at(3),2,"Hello World!"}); std::shared_ptr<std::string> test_str(createNewString(), [](std::string* ptr) { delete ptr; }); std::cout << test_str << ":\t" << *test_str << std::endl; return 0; }
output:
1 2 3 4 5 4 2 Hello World! 0x581458: Hello World! Unicode Character: ‘
The Qt SDK should probably be recompiled when using a different compiler version, I can’t make any guarantees this will work 100% but should be enough to play with c++11!
Thank you for the instructions. Worked perfectly.