4

I'm trying to build a C++ app on Windows using Qt.

My setup is:

  1. Installed Vs2008,2010,2012
  2. Installed Qt 5 RC1

Now when I #include and try to use std::unique_ptr it tells me that its not defined, so I looked in VS2010 headers and saw that _HAS_CPP0X needs to be defined, so I added it to the .pro as DEFINES += _HAS_CPP0X

This still had no effect, so I ctrl+clicked the #include memory only to find its using the memory header from:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include

Which really doesn't have any std::unique_ptr in there!

Surely it should be looking at:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include ?

I figured I'd include memory via the full path but this still fails with errors in the included memory header itself relating to C++11 things such as move and rvalue references.

So what I'd like to know is:

  1. Can Qt on Windows use C++11 features supported by Vs2010?
  2. If yes then how?
  3. If no then I'm very disappointed as developing a cross platform Qt 5 app on Linux means its not cross platform since its impossible to build it for any other platforms!

Edit:

Just so the solution to this is clear: Download the source of Qt5 and build it with MinGW and you'll be all set (inc the C++11 pro option in the accepted answer).

paulm
  • 5,629
  • 7
  • 47
  • 70

3 Answers3

2

You can simply put:

CONFIG += c++11

in your .pro file. But upgrading your compiler to a recent g++ or clang is highly recommended.

user1095108
  • 14,119
  • 9
  • 58
  • 116
  • 1
    ...note that switching compiler also means needing re-compile whole Qt, which requires a bunch of pre-requisites such as scripting languages to be installed first. So, one alternative is just to develop on Linux now, and add Windows support once there are pre-built Windows binaries for something else than VC++ 2010... I hope it is not long. – hyde Jan 04 '13 at 14:24
  • A couple of clicks and you have all the basic prerequisites. Consider it a worthy investment of time. – user1095108 Jan 04 '13 at 14:27
  • Accepting this answer since the only way I got this to work on Windows was using a newer MinGw/g++ – paulm Jan 05 '13 at 22:51
0

I'm running QT Creator 2.6.0 so assuming the option menu hasn't changed if you go to Tools > Options > Build & Run and then look for the Compilers tab you should see a list of Automatically detected compilers, hopefully including Microsoft Visual C++ Compiler 10.0. If not it can be manually added.

As for C++11 support, if you are using cmake and imported the project into QT Creator as such you can add this to your cmake file: set(CMAKE_CXX_FLAGS "-std=c++0x")

If you are using qmake then per the manual set QMAKE_CXXFLAGS += -std=c++0x

Edit: That said Visual Studio 2010 (Visual C++ 10.0) turns on c++11 support by default although it should be noted it is only a subset, here is a related question.

Community
  • 1
  • 1
Ryan Maloney
  • 552
  • 4
  • 5
  • You're right that the options are the same, but choosing that compiler results in build errors that cl.exe isn't found? And those qmake flags with the compiler set up by default complains that it doesn't know what -std=c++0x means (unrecognised option). – paulm Dec 12 '12 at 19:35
  • I believe this will answer your question on cl.exe http://stackoverflow.com/questions/8800361/cl-is-not-recognized-as-an-internal-or-external-command and I've added a note with regard to c++0x. – Ryan Maloney Dec 12 '12 at 20:01
  • I'll give the adding to the path ago tomorrow, although I'm sure it already is in the path since running cl.exe from cmd.exe works! – paulm Dec 12 '12 at 20:08
  • 2
    `-std=c++0x` is a `g++` flag and is not recognized by Visual C++ 2010/12. – Nathan Osman Dec 22 '12 at 21:18
-1

NO

Can Qt on Windows use C++11 features supported by Vs2010?

You have to get Visual 2012 for that.

If no then I'm very disappointed as developing a cross platform Qt 5 app on Linux means its not cross platform since its impossible to build it for any other platforms!

On mac, use XCode 4 compiler CLang 2 and on any platform a compiler based on GCC 4.7 works

dzada
  • 5,344
  • 5
  • 29
  • 37
  • Even though VS2010 does support many C++11 features such as auto/unique_ptr/lambda's etc? – paulm Dec 12 '12 at 15:26
  • Hi auto and nullptr yes. unique_ptr, I don't think so, but check here : http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx – dzada Dec 15 '12 at 10:31
  • But if I open VS2010 IDE instead of QtCreator, and create a hello world with std::unique_ptr it seems to be supported since it builds/runs/etc. – paulm Dec 15 '12 at 10:49
  • That is great, I don't know the details, I know that move semantic is not suported in 2010, and for (x:y) is not, and other stuff, you can see the details on this web page. I know that is partially supported, atomics are not ... and so on – dzada Dec 15 '12 at 14:13
  • That blog must be out of date or something: http://msdn.microsoft.com/en-us/library/dd293668.aspx "Visual C++ 2010 introduces move semantics into the Standard Template Library (STL)" – paulm Dec 15 '12 at 14:38
  • Yes it is possible, also recently at a C++ event, they announced and released a preview of the compiler with new features (compare to the v110 = 2012) this added initializer list variadic templates and other stuff. But why don't you want to build with nov 2012 CTP or 2012 ? or even gcc 4.7 port ? – dzada Dec 15 '12 at 16:39
  • Seems at http://qt-project.org/downloads there is only msvc2010 version for windows, I guess I could download the source version and MinGW and try to build that. – paulm Dec 15 '12 at 20:35