Compiling Qt 4.8.X for Visual Studio 2012

Compiling Qt 4.8.x for Visual Studio 2012

Qt 4.8.3 with Visual Studio 2012 x64 (should also work with 4.8.2)

  1. Install Strawberry Perl

  2. Download Qt 4.8.3 source code from http://qt-project.org/downloads

  3. 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
  4. Replace qt-everywhere-opensource-src-4.8.3-x64\src\3rdparty\webkit\Source\JavaScriptCore\wtf\HashSet.h by this HashSet.h.

  5. Start "VS2012 x64 Native Tools Command Prompt"

  6. Switch to Qt 4.8.3 source directory (the directory that contains configure.exe)

  7. Run:

    configure -mp -opensource -nomake demos -nomake examples -platform win32-msvc2010
  8. 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)

How to set Visual Studio 2012 RC Compiler for Qt instead of MinGW?

As far as I know Qt does not yet support Visual Studio 2012 RC. However, I managed to build Qt 4.8 with Visual Studio 2011 beta (the predecessor to Visual Studio 2012 RC - they just decided to rename it) myself. It required making some changes to Qt source code before compiling. Here are the steps I used:

  • Copy mkspecs/win32-msvc2010 to mkspecs/win32-msvc2012 and edit the qmake.conf file to specify _MSC_VER=1700.
  • Search for “msvc2010” in all files in the extracted directory and patch the ~10 places to also understand “msvc2012”
  • In a Visual Studio command shell, cd to tools/configure, run a previous version of qmake (which you need to already have), and then run nmake to update your configure.exe.
  • Search for “make_pair<” in all files and remove the template arguments.
    • This may not be required in VS 2012; in VS 2011-beta I got compile errors with make_pair when template arguments were specified.
  • In src\3rdparty\javascriptcore\JavaScriptCore\runtime\Structure.{h,cpp} change the make_pair calls to explicit JSC::StructureTransitionTableHash::Key constructor calls.
  • Edit src\3rdparty\clucene\src\CLucene\config\define_std.h to comment out _CL_HAVE_HASH_MAP and _CL_HAVE_HASH_SET
  • In a Visual Studio command shell, run the configure program that is installed with the source, e.g.: configure.exe -debug-and-release -platform win32-msvc2012 -opensource
    • [Optionally] add '-nomake demos -nomake examples' to the command line to save build time, and/or '-mp' to build in parallel
  • When the configure is complete, type nmake to start the build. This will build debug and release versions of all the libraries as well as release versions of all the tools (designer, etc.).

It took a little work but it worked for me and I now have dozens of Qt applications up and running, so I figured I'd share with anyone else who wants to build Qt 4.8.x on Visual Studio 11 (Visual Studio 2011 beta or Visual Studio 2012 RC.)

If this seems too complicated, just wait a bit; I'm sure Qt will support Visual Studio 2012 soon.

Building a Qt 4.8 application on Visual Studio

You would have to compile Qt4.8 from source if you want to use Visual Studio 2015 with that exact version (4.8). There is no official release of Qt4.8 that was built using msvc2015.

If you are really tied to the Qt4.8 version, my suggestion would be to download and install lower version of Visual Studio and the corresponding compiler, e.g., msvc2008.

Although, before doing so, I would confirm if the project you are trying to build is really bounded to the Qt4.8 version. It might work as expected with the higher Qt version; or with some added modifications.

Is it possible to work with Qt4 projects in Visual Studio 2012 using add-ins?

Yes it is possible with the VS addin 1.2.2. I use this addin version and Qt 4.8.1 in Visual Studio 2012 together.

The addin has limitations for Qt4, but it does the whole moc and ui stuff for you.

The limitations are:

  • you must specify the Qt4 include directories and lib paths self (not clickable)
  • you have no Qt 4 file templates (but still works, after changing the include directives of the Qt4 header files according to the Qt4 file structure)

Qt Versions

QT 4.8.x and VS2012 prebuilt binaries?

I finally (after some hours searching) found it:

http://www.tver-soft.org/qt64

They have also 64bit builds, in case someone is interested also.

Qt 4.8.5 QVariant unresolved external symbol Visual Studio 2012

The linker is telling you that you didn't define the virtual QVariant CBDatabase::data(QModelIndex const &,int) const member of your CBDatabase class. The missing member does not come from Qt, it's part of your own code. The issue has nothing to do with Qt. To reproduce it, the following suffices (that's the whole thing, doesn't need linking with Qt):

class QModelIndex {};
class QVariant {};
class CBDatabase {
public:
// declaration, no definition
virtual QVariant data(const QModelIndex &, int) const;
};

int main() {
CBDatabase db;
db.data(QModelIndex(), 0);
}


Related Topics



Leave a reply



Submit