How to Build Qt For Visual Studio 2010

How to build Qt for Visual Studio 2010

First of all, it’s very important to understand that for using Qt with Visual Studio 2010, it's not possible to use the pre-built binaries which were made for Visual Studio 2008, but you have to compile it from source.

Downloading Qt

On https://www.qt.io/download/

Update 2017: the latest Qt 4.x branch (Qt 4.8.6) has 2 pre-built packages, which are now in the archive section:

  1. http://download.qt.io/archive/qt/4.8/4.8.6/qt-opensource-windows-x86-vs2010-4.8.6.exe
  2. http://download.qt.io/archive/qt/4.8/4.8.6/qt-opensource-windows-x86-vs2008-4.8.6.exe

You should not download Qt by clicking "Qt libraries 4.8.6 for Windows (Visual Studio 2008, 218 MB)", but by clicking on the "zip" link above it.

link-selection

On that link, you get a big zip file like "qt-everywhere-opensource-src-4.8.6.zip". Unzip this into a folder and make its path something nice and small, for example "E:\Qt"

Visual Studio Command Prompt

Now that we have the sources, we need to build the binaries. To do it, open the Microsoft Visual Studio 2010\Visual Studio Tools\Visual Studio Command Prompt (2010) link from your start menu, or even pin it to the taskbar (a good idea). This is a special command prompt which has all the variables set for building with Visual Studio 2010 tools.

Once within the command prompt, navigate to your extracted Qt folder using old-school DOS way, which means you have to change drive letter by E:, enter directories by cd Qt and list dir contents by dir. You can use the tab key for helping you with the directory names. When you have arrived at the correct directory, a dir command should return something like this.

command line

Building Qt

Now it’s time for configure and build. For configuring a minimalist Qt, I'm using the following flags with configure.exe. Just copy and paste it into the command line. Look in the Qt reference manual for what flag to use or not to use.

configure.exe -release -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-qt3support -no-multimedia -no-ltcg

Once configure.exe has finished (it was 10 minutes for me), you'll need to start the build process. It will take about 20-30 minutes with the above flags. To start it, just type:

nmake

Setting environment variables

Basically, we are done. All you need to do is to set your environment variables (QTDIR and PATH), which tell programs where to find Qt. If you are on Windows 7, you can use the following command to set QTDIR to your installation dir.

setx QTDIR e:\Qt

For setting the PATH, I strongly recommend using Path Editor. Within Path Editor

add the directory of Qt\bin to your PATH

(it doesn't matter if it's in system path or user path)

If you prefer to use Control Panel\System\Environment Variables, then you can set these there, too.

Qt Visual Studio Add-in

Here you go, after a logoff-logon or a restart, all the Qt demo applications should start correctly (I recommend have a look at bin\qtdemo.exe). Now you can download and install the Visual Studio Add-in (qt-vs-addin-1.1.9.exe) from the Qt download page, it will work perfectly.

addin

Appendix A: Official Instructions:

There is a page at the official wiki at the Qt website called Qt 4.8 Installing Qt for Windows, but I found it lacking important information.

References

Qt DevNet forums

Recommended flags for a minimalistic Qt build

Building Qt 4.5 with Visual C++ 2010

How to compile Qt as static

Qt 4.8: Configure options for Qt

Edit the PATH environment variable in

Windows without pain - op111.net

Building Qt 4.5 with Visual C++ 2010

It worked for me to build just as if it was vs2008, but using the vs2010 tools:

  1. Open vs2010 command prompt. cd into the top-level Qt directory.
  2. configure.exe -platform win32-msvc2008 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast
  3. nmake

installing Qt for VS2010

You don't need QtCreator AND visual studio.

QtCreator is Qt's own IDE and uses g++/mingw as the compiler (included in the download).

Qt includes QtDesigner - the graphical UI designer that you can use with visual studio or QtCreator.

If you want to use VS, install the qt-vs-addin and download the VS builds of the Qt libs.

If you want to use QtCreator, download the mingw builds of Qt.

Or in both cases you can download the source and build it from scratch using wither QtCreator or VS.

edit: You can make QtCreator use the VS compiler backend - in which case you should download the VS build of Qt. Personally I have never done this - if you are using VS then you may as well use the VS ide.

edit2: The free express version of VS can't use plugins - so its a bit of pain to use with Qt. In this case you should probably use QtCreator.

Compiling Qt - Visual Studio 2010

You mean something like this?

Here is the official documentation.

Installing Qt5.1.1 and making it run with Visual Studio 2010

  1. First, ensure that your Visual Studio installation contains a 32-bit compiler (the official Visual Studio 2010 packages only support 32-bit compilers)
  2. Then, ensure that you've downloaded and installed one of the packages that are marked "Qt 5.1.1 for Windows 32-bit (VS 2010)" from http://qt-project.org/downloads
  3. If Qt Creator still doesn't auto-detect your compiler, add it manually: http://qt-project.org/doc/qtcreator-2.8/creator-tool-chains.html
  4. If you had to add your compiler manually, also add a Kit to combine your compiler with your Qt libraries: http://qt-project.org/doc/qtcreator-2.8/creator-targets.html


Related Topics



Leave a reply



Submit