Compiling Qt 4.8.x for Visual Studio 2012 - c++

What steps should I take to compile Qt (version 4.8.x) for Visual Studio 2012?
I already carefully followed the instructions in the accepted answer of this question (which is for VS 2010), but WebKit module failed to compile (I'm not sure if the error message was logged anywhere during compilation).
I also saw this question which asks the same, but for VS 2012 RC (which is why I thought this wouldn't be a duplicate question). Furthermore, the answerer says he has compiled Qt for VS 2011 Beta, so there's a chance it may not work for VS 2012 (RTM). The compilation takes a lot of time, which is why I have not tried it yet.
At least one problem I realized is that there's no win32-msvc2012 directory in Qt\mkspecs. Should I just create that directory and copy the files from win32-msvc2010, possibly with some modifications?
Another sub-question is whether I should make some modifications to Qt sources before starting compilation.

Qt 4.8.3 with Visual Studio 2012 x64 (should also work with 4.8.2)
Install Strawberry Perl
Download Qt 4.8.3 source code from http://qt-project.org/downloads
Go to mkspecs\win32-msvc2010. Open qmake.conf and change:
QMAKE_COMPILER_DEFINES += _MSC_VER=1600 WIN32
to:
QMAKE_COMPILER_DEFINES += _MSC_VER=1700 WIN32
Replace qt-everywhere-opensource-src-4.8.3-x64\src\3rdparty\webkit\Source\JavaScriptCore\wtf\HashSet.h by this HashSet.h.
Start "VS2012 x64 Native Tools Command Prompt"
Switch to Qt 4.8.3 source directory (the directory that contains configure.exe)
Run:
configure -mp -opensource -nomake demos -nomake examples -platform win32-msvc2010
Followed by:
nmake
I programmed a tool called BlueGo which automatically downloads Qt 4.8.3 and builds it with VS2012 x64: http://bluego.vertexwahn.de (also works with VS2010 x64) (it just does what I described above automatically)

Qt 4.8.4 needs less tweaking than described by Vertexwahn above.
The HashSet still has to be fixed (see fix of Vertexwahn) after Qt has been extracted from archive.
Platform win32-msvc2012 is supported out-of-the-box though (also works for 64bit in the 64bit environment, don't ask why they name it Win32).
So simply replace the HashSet.h and compile.

Just creating a win32-msvc2012 directory with the changes below didn't work for me, there is more editing necessary. What exactly is necessary is described in the thread you already linked.
What I did, I went to win32-msvc2010.
There, open qmake.conf and change
QMAKE_COMPILER_DEFINES += _MSC_VER=1600 WIN32
to
QMAKE_COMPILER_DEFINES += _MSC_VER=1700 WIN32
Then I could configure using win32-msvc2010.
Also, I used these changes: http://qt-project.org/forums/viewthread/17771 (alzi's Version)

Related

How to use Clang kit with Qt Creator on Windows?

(this question similar to this one but is not the same)
I'm using QtCreator on Windows platform, usually with vc toolchain.
sometimes with MinGW-W64, so for now, I'd like to try clang for some reasons.
unlike the post above - I don't use Qt library , just qtcreator as IDE, so I suppose I don't need to re-build it and QtCreator for a using clang kit, is it correct?
there are a few questions about that:
CLang distribution doesn't contain platform or even c/c++ runtime library, should i use it from vc kit? or/and MinGW runtime? how to switch between?
Correct my understanding please if it's wrong - for Win platform, clang has two options to use: 1) normal use - clang.exe ,as on any other platform 2) clang-cl.exe - additional layer which "looks like" cl.exe, and just parses cl command line keys and calls normal clang.
as I understand there is no LLDB for Windows platform , can I use GDB or CDB depends of the used runtime lib and binary format of the executable?
and finally - how to configure all this in qtcreator?
The following steps apply only to MSYS2 64-bit installation of QT Creator 4.5.1 (install instructions here), where you also have MinGW-w64 and mingw32-make installed on MSYS2; and you are building a non-QT C or C++ application.
These instructions use QMake, because QBS doesn't support MSYS2 clang. Well, QMake doesn't support it either, but I did figure out how to add support to QMake and I didn't figure out QBS.
There is QMake support for MSVC-clang but it outputs MSVC makefiles, so you can't build it with MSYS2 make. So that does not apply to us.
Install clang with pacman. I used pacman -Ss mingw-w64-x86_64-clang, your flavour may vary.
Add support for clang to QMake:
In the MSYS2 shell, go into /msys64/mingw64/share/qt5/mkspecs/
Do cp -a win32-g++ win32-clang-msys
Edit win32-clang-msys/qmake.conf and change gcc to clang, and g++ to clang++ (2 places each)
In the same file, take out -fno-keep-inline-dllexport -mthreads which are not supported by clang.
In QT Creator, set up a new Kit:
Go to Manage Kits.
Add a Custom Compiler for C and browse to the installed path (/mingw64/bin/clang.exe under your MSYS2 install).
Add a Custom Compiler for C++ as clang++.exe in the same place)
Add a manual Kit called Clang and set those two compilers as its compilers.
In the manual kit config set "Qt mkspec" as win32-clang-msys
Set "QT Version" to something. Even though I am using a non-QT project, the IDE doesn't like using the kit if "Qt version" is set to None.
Now you can attempt to build your project with the Clang kit and QMake.
I initially tried with QBS and the build failed due to this bug . But the build commands do succeed if I copy-paste them and cut out the bogus -target switch. So for QBS users I guess you have to switch to QMake in the meantime until they fix that bug.
Troubleshooting: I sometimes got an error Project ERROR: failed to parse default search paths from compiler output. This is a problem with QMake's lack of support for clang. The error tended to not occur if I built in a subdirectory of the .pro file, but did occur if I built in a sibling directory.
As a workaround: go back into win32-clang-msys/qmake.conf. Change the first clang back to g++. Then "Run Qmake" (from QT creator or commandline), then change it back. The first time you run QMake it writes the file .qmake.stash and then does not need to generate it again. The contents of this file were bogus for me but building seemed to work anyway.
Undefined references: I found that linking with -static produced a bunch of undefined references to __imp__cxa_ names. Not sure what the problem is here but maybe related to the bug with generating .qmake.stash. I guess the Qt developers would need to officially add non-MSVC Clang support to QMake.
Multiple definitions: The CLang linker gave multiple definitions for inline DLLexport functions. I found no workaround yet for this; g++ has -fno-keep-inline-dllexport to avoid this problem but CLang 5 does not support that flag.

Building QT for msvc2015 - and get working projects?

There already is a quite related question (rq) here, but it is not specialized enough and my reputation is not high enough to ask for more advice in the comments ... yet, time is running and I've got to get somewhere.
Once the original question is answered, this one can and should be deleted.
What I want: Working in Visual Studio 2015, using the qt-library. That's it.
What I did:
Install vs2015, works
Download the qt5.5.0 source, built it following the (rq) instruction using jom (nmake worked the same, just was slower)
Install the qt package extension for vs2015, also following (rq)
The first error: The building-process didn't create any mkspecs, so i wasn't able to set the directory in the QT-options in visual studio: "This QT version uses an unsupported makefile generator (used:, supported: MSVN.NET, MSBUILD)"
I tried to hack that by replacing it with the mkspec-folder of an installed version to I was able to select the qtbase-folder in the Qt Options.
Played around with the library-directories, the include-directories and the additional-dependencies of the VS-Project. No matter what I did, the include-files where not found.
As this didn't work out, I installed qt 5.5.0 mingw492_32 with the installer. Using that I was able to create a new project with the QTCreator. It compiled in the QTCreator. After that I executed
qmake -platform win32-msvc2015 -tp vs
to convert the project into a Visual-Studio-project, while qmake was the executable from the previously BUILT version, not the installed one, the include-files where still not found in visual studio.
What am I doing wrong? The library-directories, the include-directories and the additional-dependencies look fine to me in the converted project.
EDIT 1:
I followed the walkthrough and everything built successfully. Yet, the mkspecs-folder is still empty. Creating a Qt-Widget-application with the Qt Creator endts up in a crashing app (no changes were made to the default code):
Second Chance Assertion Failed: File minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp, Line 980
Calling
qmake -platform win32-msvc2015 -tp vs
also isn't successfull:
qmake -platform win32-msvc2015 -tp vs
WARNING: Unable to generate output for: D:/_Daten/_Studium/Bachelor-Thesis/Visual-Studio/VISAR-FSA/GuiTest/Makefile.Debug [TEMPLATE vsapp]
WARNING: Unable to generate output for: D:/_Daten/_Studium/Bachelor-Thesis/Visual-Studio/VISAR-FSA/GuiTest/Makefile.Release [TEMPLATE vsapp]
EDIT 2:
Concerning the mkspecs: Turns out I had to call both:
jom -j 8
jom install
Now all mkspecs are created. The official documentation made me think that the second one only was an option for the build when a destination path was set.
Yet, a freshly created Qt Widget Application in Qt Creator, with the built and installed QT-version and the correct compiler, still won't compile. A LNK2019 occures in [qtmain.lib(qtmain_win.obj)], telling me that there is a link to a symbol "__imp__CommandLineToArgvW#8" in function "_WinMain#16", that was not resolved.
Here is a complete walkthrough:
How to compile Qt 5 under Windows or Linux, 32 or 64 bit, static or dynamic on VS2010, VS2012, VS2013 or VS2015 Express or g++.
You might want to uninstall all previous Qt.
I have Qt built for VS2015 as well as VS2013 and for 5.50 onwards it shouldn't need anything particularly special to get it to build successfully. I tend to use a cut down version of the Walkthrough that #jafar's mentions (and also closer to the method in the official docs')
Clone the qt5 repository or unzip the source
Start a command prompt. IMPORTANT: create the correct 'VS2015 x86 or x64' prompt
DON'T edit the msvc-desktop.conf as mentioned in the Walkthrough. (Qt can't be built with the /MT flag)
Run configure:
configure -debug-and-release -opensource -platform win32-msvc2015 -opengl desktop -nomake examples -nomake tests
Build with jom -j 8 (I find you get diminishing returns beyond that) or nmake. If you omit the examples and tests I can build the whole of qtbase in about 10-15 minutes
Run jom install or nmake install

Building Qt5 with Visual Studio 2012 / Visual Studio 2013, and integrating with the IDE

How do you get Qt5 to download and integrate with Visual Studio 2012? What are some of the problems you will encounter, and how do you solve those problems?
UPDATE re. Visual Studio 2013
Successes are reported with Visual Studio 2013 as well, and the notes are being maintained for VS 2013.
Also note that the focus of the question is strongly on just building Qt with Visual Studio. There are also notes about integrating with the Visual Studio IDE
This method is tested to work on Visual Studio 2013. Pre-built binaries using Visual Studio 2012 and 2013 are available here, including OpenGL versions.
Step 1: The Setup
Download and install RapidEE here. RapidEE is a windows environment variables editor. It is extremely useful for the rest of this process (and just in general).
Install the DirectX 11 SDK. It is now part of the Windows 8 SDK, so you first have to install the DirectX 10 SDK, which you can get here (but see warning in next sentence). If you have the Visual C++ 2010 Redistributable Package installed, and you probably do (it is automatically installed along with VS 2010), follow the steps outlined here to assist with the DirectX 10 installation. Once you have the DirectX 10 SDK installed, download and install the Windows 8 SDK here, which contains the DirectX 11 SDK. Yes, this is a pain, but unless you know you have the DirectX 11 SDK, the Qt build will fail.
Install Python for Windows (I've heard 2.6+, working with 3.3) from Python.org or Anaconda Python.
Install Perl for Windows from ActiveState.
Step 2: Gitting (and building) Qt5 (yes, that means Git)
Follow the installation guide for Windows at the qt-project website.
Summary
To summarize the details from the above link and from the following notes (PLEASE SEE FOLLOWING NOTES if you have any errors; they might be answered):
Uninstall Avast (if you have this installed) to avoid build errors. Yes, that literally means uninstall it. Remove it 100% from your system. Deactivating it will not work. See detailed notes below.
Note for the first steps: DO NOT use SmartGit for the first git pull, below (unless you really know what you're doing), as SmartGit's defaults will pull everything, and that's not what you want.
Git for Windows must be installed.
Decide where you want to put the Qt installation, and cd to the directory that will contain the new installation from any Command Prompt window. (Because the process is so fragile and error-prone, I personally put it directly in C:, but this is likely not necessary).
From the above directory, execute:
git clone git://gitorious.org/qt/qt5.git qt5
This is fast. Once complete, you should be on the 'stable' branch, but you can always run git checkout stable after cding into the newly-created qt5 directory, just to be sure. Using git checkout 5.4.1 is confirmed to work with VS2013 64-bit.
Close out of your current command prompt window (if it's not a Visual Studio command prompt window) before proceeding to the next step. This is to make sure you're using the Visual Studio command prompt window in the next steps.
Next run the 32-bit (x86) or 64-bit VS Tools command prompt (depending on whether you're building Qt5 as 32- or 64-bit). To access this, you must find it through the Start menu - go to Program Files -> [Microsoft] Visual Studio 2012/2013 -> Visual Studio Tools, and you'll see it in there with a funny name; the name should include the phrase Native Tools; the 32-bit version will have x86 in the name and the 64-bit version will have x64 in the name.
cd into the newly-created qt5 directory from the step above.
From within the Visual Studio command prompt, the remainder of the Qt submodules must be downloaded:
perl ./init-repository --no-webkit
It takes kind of a while to execute this step, because it has to download a lot, but it's not too terrible on a decent connection.
Then download any remaining OPTIONAL submodules that init-repository does not download - SmartGit works well only starting at this stage (see comments below).
Once the download of Qt is complete, the following command prepares the build environment (it should also be executed using the [32|64] VS Native Tools Command Prompt):
configure -developer-build -opensource -confirm-license -mp -nomake examples -nomake tests -debug-and-release -c++11 -no-warnings-are-errors -platform win32-msvc2012.
Notes on this command line: the c++11 option might not be necessary with the VS2012 compiler, but works with VS2013; the -no-warnings-are-errors is necessary in case you get errors on a 64-bit automatic build of ANGLE; -platform is automatically set to win32-msvc2012, so by default the 32-bit build of Qt is used, and -platform probably does not need to be supplied at the command line (EVEN if you have previous versions of VS installed). For VS2013, use -platform win32-msvc2013.
It takes a few minutes to execute this step, but it's not so bad.
Finally, the command to actually build Qt on the system (also run within the VS Native Tools Command Prompt) is simply:
nmake
Expect to wait hours for the build to complete. If you specified an output folder with -prefix (see notes below), then use nmake install, otherwise that's it.
NOTES:
General Notes
In case you're confused from the above-linked documentation, just an FYI that the ANGLE library will be used (by default) instead of OpenGL, and that's why you had to install DirectX 11, above.
Make sure that you use the VS Native Tools Command Prompt to run all commands from the above link (that is, perl .\init-repository --no-webkit, configure, and nmake). You will use the [32|64] bit command prompt (x86 or x64), depending on whether you are building Qt as 32-bit or 64-bit. If you install perl with the Command Prompt open (make sure it is in the PATH), you will need to restart the Command Prompt for perl to be recognized as a command.
When running "init-repository" (from the steps in the above link), it's not clear from the documentation, but you must execute this via perl; i.e. perl ./init-repository --no-webkit. The configure and nmake commands, however, are called directly.
One very useful option to pass to configure is -mp, which causes Qt to build on multiple cores in parallel, significantly speeding up the (long) build time.
To specify an output folder add the -prefix [outfolder] to the configure command. For example, use -prefix %CD%\output\x64\vc12 would be a suitable output (sub)folder for a 64-bit Visual Studio 2013 (12.0) build.
Unicode Support (ICU)
If you want Unicode support (via ICU), pay special attention to the instructions noted within the link above. In summary, ICU must be built from scratch in VS 2012, as the only prebuilt ICU binaries for Windows are for VS 2010. Building in VS 2012 is painless - simply locate the ICU solution (.sln) in <icuroot>\icu\source\allinone, and build in both Debug and Release mode (either in 32-bit or 64-bit mode, depending on which mode you're building Qt in - DO NOT build in the other bitness, because ICU will overwrite the output folder with the binaries). (The Qt build process will properly locate the debug vs. release build of ICU.) It should build without errors. Then, add the path to <icuroot>\lib as a string entry in a (probably) NEW Windows environment variable called "LIB" (you can use Rapid EE for this; make LIB an "expandable string" in RapidEE even though there's only 1 entry), and also add the path to <icuroot>\include as a string entry in a (probably) NEW Windows environment variable called "INCLUDE". (Note: Adding these paths to the PATH variable will not work.) After Qt is built, you can remove all of these entries you've just added. Also, do add the runtime path to the ICU dll's (<icuroot>\bin) to the environment's PATH variable, or the Qt build process (specifically, when uic.exe runs) will give a deceptive and misleading error. Finally, on the configure command line (below), be sure to add -icu as an additional command-line parameter.
ICU Failure:
Currently, there seems to be a bug building Qt5 with the VS2012 compiler WHEN ICU IS ENABLED. Specifically, qtbase\src\corelib\codecs\qtextcodec.cpp Line 688 (Qt5 v5.02) fails to return a codec for codec name "US-ASCII" (the codec is NULL), causing "lrelease.exe" to crash when trying to dereference the codec later (I have lost track of that file/line number, but it is an obvious dereference of the NULL codec variable). Unfortunately, this means that to my knowledge, WebKit cannot be built with (at least the) 32-bit build of Qt5 with the VS2012 compiler, because WebKit requires ICU.
If anyone is able to build Qt5 with the VS2012 compiler with ICU enabled, please update this Wiki saying so.
ICU Clarification:
If you have ICU in your path, Qt will automatically built it. In other words, the flag "-icu" is there implicitly. However, this causes an error with "lrelease.exe" as mentioned above. So the way around this would be to add the flag, -no-icu to the configure command
Additional Submodules
If you want submodules in addition to the default submodules, you can use SmartGit (or command line) after you complete the init-repository command. SmartGit is perhaps easiest, because you do not need to copy the path to the command line, but can use the user interface directly.
WARNING: DO NOT DOWNLOAD THE OPTIONAL qlalr SUBMODULE, as it will not build in combination with the overall Qt build, and is not necessary for users of Qt, but is only used for internal Qt development.
WARNING: A shell command line, followed by perl .\init-repository --no-webkit, must be used (NOT SmartGit); these steps will properly only download the default Qt submodules. You must not use SmartGit to clone and download the Git files from git://gitorious.org/qt/qt5.git because SmartGit does not currently handle the submodules properly. Instead, open a standard Windows shell command prompt (using any command-prompt application, not necessarily the VS Tools command prompt), and (assuming Git is properly installed on the system; a SmartGit installation might or might not do this automatically; if it does not, go to Git for Windows and install directly) type git clone git://gitorious.org/qt/qt5.git directly from the command line; perhaps follow that with git checkout stable (I'm not sure if this branch is checked out by default); then follow that with the command line perl .\init-repository --no-webkit to pull down the DEFAULT repositories (except WebKit, which requires ICU and ICU seemingly cannot be built in 32-bit Qt5 with VS2012; see comments).
The steps for downloading all necessary Qt source files therefore are:
1. Use a Windows command line to execute the initial git clone git://gitorious.org/qt/qt5.git;
2. Execute perl .\init-repository --no-webkit from within a VS Tools 2012 Command Prompt; and then optionally
3. Use SmartGit (from above link) (or equivalent) to "open an existing project" (choose the Qt5 root folder) and do a Pull from within SmartGit to download any non-default repositories (but do not download qlalr). That's it; you have all necessary and optional Qt files (including submodules) on your system.
If anybody discovers other optional submodules that fail to build and/or are for internal use only (besides qlalr), please update this Wiki to specify them.
In general, the default submodules obtained via perl .\init-repository --no-webkit are sufficient. If you know, or later find out, that you other (non-default) modules, you can always add them later.
General Problems
If at some point you get the error saying that the command "python" (or anything similar) is not recognized, just check that the folder containing python.exe (or the appropriate .exe) is part of the path variable. If it is not, add it (use RapidEE as noted above for convenience) and try what you were doing again. If it is there, make sure you have restarted your command prompt AFTER the addition of the command to the path.
Two other path-related issues are important to note (quoted from the documentation associated with the link above): "Make sure the perl executable is found in the path before the perl executable provided by msysgit, since the latter is outdated"; and "You might not be able to build if sh.exe is in your PATH (for example due to a git or msys installation). Such an error is indicated by qt5-srcqtbasebinqmake.exe: command not found and alike. In this case, make sure that sh.exe is not in your path. You will have to re-configure if your installation is already configured."
During the process, you may encounter an error using nmake on a file. If you do, just go into that directory and force build the problem file. Then begin the nmake process on Qt5 again.
Specific Problems
WARNING: You may need to disable antivirus software AND SANDBOXING during the Qt nmake process (and, to be safe, throughout this entire process). Internally, Qt executes a number of executables that antivirus programs can interfere with (sometimes silently). In particular, if you have any sandboxing software, be SURE to disable sandboxing.
WARNING: AVAST! Sandbox users: Avast Sandbox has a bug in which even when you disable Avast's auto-sandbox, the sandbox will NOT turn off and it will silently sandbox all resource files automatically created by Qt's rcc program during Qt's build process. The Qt build ALWAYS fails for any user who has installed the Avast autosandbox feature, EVEN WITH AUTO-SANDBOXING TURNED OFF. THE ONLY WAY TO OVERCOME THIS ISSUE IS TO COMPLETELY UNINSTALL AVAST! FROM YOUR SYSTEM before building Qt. You can reinstall Avast! after the Qt build is complete.
The compilation of Qt5 can take a long time (hours, even with the -mp multithreading option). Patience.
Step 3: Integrating Qt5 with Visual Studio 2012
Download and install the Visual Studio Qt5 addin. It is in the "Other Downloads" section near the bottom of the page, and will not work with Visual Studio Express.
Open Visual Studio 2012, and go to Qt Options (It's under "Qt5" on the top menu bar).
In the Qt Versions tab, check to see if Qt5 is already there. If it is not, click add, choose a version name (probably a name such as 5.x.x), and navigate to the folder containing qmake.exe (usually C:\Qt\qt5\qtbase).
Exit the Qt Options dialog.
Create a new Visual Studio Project. When you see the New Project dialog, you should see the Qt5 Projects Template option.
Once you have your new Qt Project, right click on it and select "Convert to QMake generated project". Build the project, then right click on it again and select "Convert project to Qt Add-in project". Build again, then run. You should now have a working Qt Project.
Add Qt5 to an existing Visual Studio 2012 VC++ project
This section may or may not work for you. If you run into problems or have additional/better solutions, please leave a comment or edit the appropriate step.
Right-click on your project in VS, and choose "unload project". Right click on the project again, and select "edit [project name].vcxproj". This opens the project file so you can add Qt5 to it.
Go down to the Global PropertyGroup, and add or change the <Keyword> to Qt4VSv1.0.
Reload the project, then right-click and select "Convert project to Qt Add-in project"
Wait for the conversion to finish (it does not take more than a couple seconds), then choose Qt5>Project Settings. Go to the Modules tab, and check the modules you would like your project to rely on (the basic ones are Core, Widgets, and GUI).
Following the steps here, add the directory $(QTDIR)\include.
NOTES:
If at any time you are including windows.h, you need to #define NOMINMAX before doing so to prevent conflict with qdatetime.h.
Once the above steps are done, you can make your project usable by Qt Creator by selecting Qt5>Create basic .pro file.
ENDING NOTES: If you have a question related to the information contained in this guide, please post it as a new question (not an answer here), and the answer or a link to the answer may get added.
I successfully managed to integrate Qt 5.0.2 with Visual Studio 2012 on Windows 7 based on the excellent wiki above and on this qt-project link as well. Since I made some of the steps on a slightly different way, I thought it would be valid to post it in here:
The sequence below should be executed in the exact given order:
0 - Uninstall Avast (if you have this installed) to avoid build errors. Due to an Avast bug, deactivating it will not work;
1 - Install Git (>= 1.6.x);
2 - Install Python (>=2.6.x). [python.org];
3 - Install Perl (>=5.14). [activestate.com];
4 - Install Ruby. [rubyinstaller.org];
5 - Open the Windows 7 Command Prompt (don't use VS2012 Developer Command Prompt by now);
6 - Choose any directory you want for qt5, regarding that NO SPACES ARE ALLOWED for the chosen path. I decided to use the path "C:\qt5";
7 - Back to Windows 7 Command Prompt (in my case, prompting "C:\qt5>") type:
git clone git://gitorious.org/qt/qt5.git qt5
8 - Checkout the stable version:
cd qt5
git checkout stable
9 - You'll probably receive a message confirming that this version is already stable. Close the Command Prompt;
10 - Open Visual Studio's Developers Console (All Programs > Visual Studio 2012 > Visual Studio Tools > Developer Command Prompt for VS2012) and change the current directory to the one you have chosen("C:\qt5" in my example);
11 - Download Qt submodules, ignoring webkit (common source of build errors...):
perl .\init-repository --no-webkit
12 - Now enter this huge command to configure your build properly:
configure -developer-build -opensource -nomake examples -nomake tests -nomake demos -debug-and-release -c++11 -mp -nomake webkit -confirm-license
13 - Next, ensure that the module qlalr will NOT be built. To do this, open Windows Explorer and navigate to your chosen Qt directory ("C:\qt5" in my example) and check if the folder qlalr exists. If so, delete it;
14 - Time to build... Possible build errors would come from secondary modules (such as webkit), which don't affect the main Qt functionality (webkit itself should not be a problem since we've previously set the configuration not to build it). We can then ignore them and also keep the build running on independent modules:
nmake /I /K
15 - To conclude integration, follow the step 3 of the community wiki above("Step 3: Integrating Qt5 with Visual Studio 2012").
Just want to mention that there is a prebuilt version of Qt 5.2 for Visual Studio 2012 available at http://qt-project.org/downloads. So if you don't have a special interest in building Qt 5 from sources you can use the prebuild binaries, too.
There are also several precompiled (x64) binaries for different compiler versions available at the Tver-Soft website.
I was finally able to compile QT 5.1 (git) with QWebKit on Windows 8 x64 using Visual Studio 2012 and figured I'd share my experience with those that had problems as well.
Did step 1 and 2 as stated in the above post. I tried to do step 3 but SmartGit pulled a bunch of extra projects that wouldn't compile with Qt5. I was able to solve most of the problems by cloning from a different fork (e.g. https://qt.gitorious.org/qt/qt3d/), but this became too tedious to do for every extra module, so I decided against compiling any of them.
The post at ICU support in a 32-bit build of Qt5 with the VS2012 compiler causes Qt5 build failure; Webkit is also therefore unbuildable told me how to fix the ICU problem.
Download the source code at http://download.icu-project.org/files/icu4c/51.2/icu4c-51_2-src.zip and add the line
#define U_CHARSET_IS_UTF8 1
to the file %ICU%\source\common\unicode\platform.h , where %ICU% is the path to the ICU source code.
Open %ICU%\source\allinone\allinone.sln file in Visual Studio 2012 and compile. Add %ICU%\bin to your path
set PATH=%ICU%\bin64;%PATH%
Then I ran the following command in the QT root directory
configure -platform win32-msvc2012 -opengl desktop -opensource -debug-and-release -I %ICU%\include -L %ICU%\icu\lib64 -mp -qt-freetype -icu
At this point I started to suspect that no one tried to do what I was doing, because nmake started to complain about unexpected lines in the makefiles (all of which had the extension DerivedSources, e.g. Makefile.JavaScriptCore.DerivedSources and Makefile.WebCore.DerivedSources))
(set PATH=<stuff>;%PATH%) && ....
do the set PATH manually before running nmake and delete the characters up to and including && e.g.
(set PATH=<stuff>;%PATH%) && perl -ne "print $1" css\CSSPropertyNames.in ...
Becomes
perl -ne "print $1" css\CSSPropertyNames.in ...
Finally, one of these files will try to call win_flex.exe (or win-flex.exe) instead of flex. I changed it to flex.exe and everything finally compiled (Had to change it twice, because I think the file got regenerated).
Brief experience with a program that uses QWebKit and linked against this build leads me to believe everything is fine.
--Update--
Just to be complete. According to What does (set PATH=...;%PATH:)=^)%) mean in a Windows shell script, and how can I overcome failure of this line in the context of a Qt5 nmake build? (which points to http://qt-project.org/forums/viewthread/20605) most of the Makefile problems should be solvable by using jsom instead of nmake (although I still wonder about win-flex.exe)
compile Qt 5.5 with visual studio 2015:
1- Modify configure.bat in qtbase directory so it can generate configure.exe (just the first 18 lines)
#echo off
set QTSRC=%~dp0
set QTDIR=%CD%
rem if not exist %QTSRC%.gitignore goto sconf
echo Please wait while bootstrapping configure ...
for %%C in (cl.exe icl.exe g++.exe perl.exe) do set %%C=%%~$PATH:C
rem if "%perl.exe%" == "" (
rem echo Perl not found in PATH. Aborting. >&2
rem exit /b 1
rem )
if not exist mkspecs (
md mkspecs
if errorlevel 1 goto exit
)
rem perl %QTSRC%bin\syncqt.pl -minimal -module QtCore -outdir "%QTDIR%" %QTSRC%
rem if errorlevel 1 goto exit
2- configure -opensource -confirm-license -mp -nomake examples -nomake tests -release -c++11 -no-warnings-are-errors -platform win32-msvc2015 -no-ltcg
3- nmake

How install 64-bit Qt on Windows with C++11 support?

IN A NUTSHELL:
My 64-bit Qt build doesn't have C++11 support.
My Qt build with C++11 is 32-bit.
Qt5 using the online installer is 32-bit
Despite having dedicated the last 3 days of my life to this, I can't get 64-bit Qt5 to build from source.
Help! Something must be incompatible in my environment, but what could it be?
So, I need to develop 64-bit Qt apps with C++11 on Windows. I've found threads/guides here, here, here, here and here, and none of them work or apply, though I note the second of these let me build Qt 4.8.3 with C++11 support (but 32-bit). The third one looks more complicated than it should be and also involves building with VS 2010, which seems like part of the problem, so I haven't tried it. I have also wasted a lot of time trying to build previous versions with different compilers, like mingw and clang, so I'm pretty sure that cl is what I need to use.
Basically, I've gotten to the point where I can build Qt4.8.3 and execute 64-bit apps from within QtCreator 2.6.1, but I can't get full C++11 support. It finds only cl from VS 10.0 which has only very limited C++11 support. Figuring out how to get it to use cl from VS 11.0 would be one solution to my problem. But when I try
QMAKE_CXX = C:/Program Files (x86)/Microsoft Visual Studio
11.0/VC/bin/cl
the build fails with a jom Error 2, and if I select the option for building with nmake I get a similar error.
Qt 5 should have full C++11 support. But when I try to build it myself from source, it fails. The reason for this seems to be that despite running configure/make from the VS2012 x64 Cross Tools command prompt, specifying -platform win32-2012 in the configure step, and specifying QMAKE_COMPILER_DEFINES += _MSC_VER=1700 WIN32 as per
this guide, in both the win32-msvc2010 and win32-msvc2012 mkspecs, it still builds with the cl from VS 2010 and that is causing some kind of conflict. Here is my configure command:
configure -static -debug-and-release -confirm-license -opensource
-nomake tests -nomake exampmles -opengl desktop -no-libjpeg -platform win32-msvc2012
And here's the linker failure when I try to build:
At the end of the top 2 paragraphs you can see that msvc-2010 is being included, and earlier in the console output (not shown) there is -D_MSC_VER=1600 in the moc commands.
So I'm at a loss, can anyone help?
Edit: I had stated that I was building 64-bit apps with Qt5, actually I'm able to build 64-bit apps (w/o C++11 support) off a build of Qt 4.8.3. If I try this with Qt5, I get this error:
LNK1112: module machine type 'X86' conflicts with target machine type
'x64'
So this leads back to compiling Qt5 in 64-bit mode, which I can't seem to do.
Finally got a 'good enough' solution by going back and rebuilding 4.8.3 in 64-bit mode, this time ensuring that it was built with C++11 support. Since a solution involving Qt5 is what would be ideal, I'll leave this open for awhile to see if anyone can figure out how to do that.
Importantly, I note that I successfully built 64-bit, C++11-supporting 4.8.3 from the same prompt I had been using to try to build 5.0. Just changed directories. So same environment, everything. And I also have downloaded all the extra prereqs required for Qt5.
You can find prebuilds of Qt 5.0.1 SDK with 64bit support here:
http://releases.qt-project.org/digia/5.0.1/latest/
Tested and working :)
I found Qt 4.8.5 windows version qt-win-opensource-4.8.5-vs2008.exe at https://download.qt.io/archive/qt/4.8/4.8.5/ for VC++ projects.

Qt 4.8.2 With GCC 4.7.0.1 Keeps Crashing

I've downloaded Qt 4.8.2 library, Qt Creator 2.5.2, and manually installed MingW with w32api version 3.13 and GCC/g++ version 4.7.0.1. My OS is Windows 7 Ultimate x64.
I can create a sample "Plain C++ project" in Qt Creator; compile and run that console application using g++ without any issue.
But I cannot run a Qt application. I used Qt Creator, created a dummy Qt Application using Creator's "Qt Gui Application" template. The project can be compiled successfully, without any error or warning. But the binary keeps crashing when I try to run (both from Qt Creator and Windows Explorer) it. Both debug and release builds crash. It crashes even before showing main window.
MingW is installed in C:\MingW and C:\MingW\bin is in PATH. Qt is installed in C:\Qt\4.8.2 and C:\Qt\4.8.2\bin is in PATH.
I analyzed generated exe of the Qt Gui Application output with Dependency Walker and found that it found all required DLLs:
c:\windows\system32\KERNEL32.DLL
c:\windows\system32\MSVCRT.DLL
c:\mingw\bin\LIBGCC_S_DW2-1.DLL
c:\mingw\bin\LIBSTDC++-6.DLL
c:\qt\4.8.2\bin\QTCORE4.DLL
c:\qt\4.8.2\bin\QTGUI4.DLL
So, what's causing the runtime crash?
EDIT
I also tried Qt's example projects: 2dpainting and addressbook - both crashed when they were launched.
You should build Qt with the MinGW compiler you're using to build your application. GCC is generally less sensitive to binary compatibility issues than MSVC is, but Qt is a big, complex framework library. If anything would expose those kinds of issues, Qt would probably be on the short list.
Building Qt is pretty straightforward, but it takes a lot of time and there always seems to be two or three patches I need to make to get things to build successfully.
The last time I built Qt (4.7.3) with MinGW, I had to make the following patches - I'm not sure whether they will still apply to Qt 4.8:
make sure not to enable C++11 mode in the compiler - there are several macros with concatenated string literals that break under the new C++11 extended literal syntax
there is a problem with how some distributions of MinGW incorporate the Microsoft extensions to float.h - I had to sometimes had to add the line:
#include_next <float.h>
to the end of the MinGW-specific float.h so the generic GCC float.h would get processed properly. I had to do this for nuwen 4.7.0 lib/gcc/i686-pc-mingw32/4.7.0/include/float.h and TDM 4.6.1 32-bit distro lib/gcc/mingw32/4.6.1/include/float.h (the 64-bit distro of TDM didn't need this patch).
patch qmake\Makefile.win32-g++ and qmake\Makefile.win32-g++-sh to remove the -static-libstdc++ option that GCC doesn't recognize (and now errors out on instead of ignores)
patch mkspecs/win32-g++/qmake.conf to move the -Wl, in the QMAKE_LFLAGS_EXCEPTIONS_ON macro to its proper place in QMAKE_FLAGS:
QMAKE_LFLAGS = -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
QMAKE_LFLAGS_EXCEPTIONS_ON = -mthreads
copy make.exe to mingw32-make.exe in MinGW's bin directory if there's not already a mingw32-make.exe
Then building Qt consists of:
set QTDIR=<location of Qt source directory> # where configure.exe is
set PATH=%QTDIR%\bin;c:\MinGW\bin;%PATH%
set INCLUDE=
set LIB=
cd %QTDIR%
mingw32-make confclean # (this should fail the first time, since there's nothing to clean)
configure.exe -opensource -debug-and-release -nomake examples -nomake demos -nomake tests -platform win32-g++ # and accept the GPL license
mingw32-make
This takes a while... hopefully nothing else will need patching.
I also got this problem. I'm a Qt n00b and tought, when installing Qt-libraries, that "well I already have Mingw installed so I skip installing the Mingw that comes with Qt". That gave me prolems. When installing mingw that came with Qt everything worked ok.
So my advice to anyone googling to this question (like I did) is to instead of using your already installed Mingw, install the one with Qt and use that (otherwise you have to build the Qt libraries within your Mingw, like the answer from Michael Burr)