Qt 4.3.4 + CMake + Visual Studio 2008 doesn’t work

Hoping to create a nice GUI for the project I am currently working on, I downloaded the commercial version of Qt 4.3.4. It installed fine, with the option of integrating with Visual Studio disabled since the integration with VS 2008 is not officially supported yet. Trolltech has already announced to support this in the upcoming version of 4.4, though.

The demo that comes with the package looks really appealing, just like how I like it: simple, themed design and fluent animated transition, which together provide the user with maximum visual satisfaction.

Trolltech is generous enough to have included all the source code of the demo so that we can play around and figure out how to mimic those fancy effects. At first I planned to use CMake to generate the project file (.sln file in the case of Visual Studio) for the demo, in accordance with all other projects that I am working on. There are also examples of CMakeLists.txt for Qt 4 projects (here is one). Despite it seemed that everything should be easily done without any hustle, it soon turned out not to be the case this time.

First, the solution file generated by CMake just won’t compile (unless it’s a single main.cpp, in which case I got it to work) if there are other Q_OBJECT classes present. I tried both QT4_AUTOMOC and QT4_WRAP_CPP, all ended up with “error LNK2019: unresolved external symbol“:

SET(SRCS src/main.cpp src/mainwindow.cpp)
SET(HDRS include/mainwindow.h)

and either

QT4_AUTOMOC(${SRCS})
ADD_EXECUTABLE(demoGUI ${SRCS} ${HDRS})

or

QT4_WRAP_CPP(MOC_SRCS ${HDRS})
ADD_EXECUTABLE(demoGUI ${SRCS} ${HDRS} ${MOC_SRCS})

Correct me if I am doing anything wrong above. After googling a bit I figured that something is wrong with the moc’ing process, but I haven’t yet found a solution. Thus I am taking CMake out of the equation temporarily.

A nice thing about qmake that comes with the Qt package is that just like CMake it can generate project files for different platforms, with an equivalent of CMakeLists.txt, projectname.pro file. With the command

qmake -tp vc -spec win32-msvc2005

one can easily get the project file (.vcproj/.sln) for Visual Studio 2005 to use. The project compiled under VS 2008 without any error, but when running under debug mode I get either “This application has failed to start because the application configuration is incorrect” if the solution file is generated by qmake or “The application failed to initialize properly (0xc0150002)” if it is created by CMake (remember I had one single main.cpp compiled). However, the release builds executed correctly.

Again I googled for a while and found out the problem might lie in the manifest files of the Qt core dll’s. Since the QMAKESPEC is set to win32-msvc2005, the manifest files of the dll’s have VS 2005 info (Microsoft.VC80.DebugCRT) embedded. When the program compiled with VS 2008 (VC90) and linked against those dll’s tries execute, there’s a conflict in configuration. Unfortunately, none of the solutions I found worked.

Now it is quite clear that for now I cannot (at least easily) debug the Qt4 programs in VS 2008. VS 2005, on the other hand, is working as advertised both in debug and release mode. Guess I would have to stick with VS 2005 for a while before Qt 4.4 is released.

An alternative plan would be trying out the 4.4 beta to see if it is a solution, while using qmake to generate the Makefile, from which to see how the CMakeLists.txt should be written.

4 Responses to “Qt 4.3.4 + CMake + Visual Studio 2008 doesn’t work”


  1. 1 Bill Hoffman March 30, 2008 at 9:55 pm

    Hi,

    This should work. I have build QT applications with CMake and VS 9 with no problem. In fact the new version of CMake has a qt based GUI and it builds fine. If you could provide me with a complete example that should work, I could try and figure out what is wrong. Here is the cmake file for the cmake-gui in qt:

    http://public.kitware.com/cgi-bin/viewcvs.cgi/Source/QtDialog/CMakeLists.txt?revision=1.16&root=CMake&view=markup

    It works with VS 9.

  2. 2 Dat Chu April 22, 2008 at 5:29 pm

    I know that this question might be a bit weird but what is the benefit of getting a VS9 solution for Qt4 with Cmake? Unless we are making changes to Qt4, can’t we just follow the conventional configure -> nmake?

  3. 3 Lol July 26, 2008 at 1:35 pm

    your doing it wrong

  4. 4 airfang October 4, 2008 at 5:46 pm

    @ Dat: I meant building Qt4 applications, not compiling Qt4.
    @ Lol: care to elaborate?


Leave a Reply