Saturday, March 12, 2011

Qt 4.7.4 / 4.8 in Visual Studio 2010







Hello folks!
I know, my posts aren’t really active lately. But who cares! At least when I post, there’s something useful or interesting to read. So, this post is a little tutorial about getting Qt 4.7.4 (or 4.8 currently) working in Visual Studio 2010. Most of you probably think that VS 2010 isn’t really native supported by Qt. But guess what, it is! There just isn’t a precompiled package to download and use. So, I will guide you through the necessary steps to get this thingy working flawlessly.
Just 16 steps!
  1. Dude what the hell. Go install Visual Studio 2010 already!
    My installation only included the VC++ compiler, since it’s all that I needed. Be sure however that you include this compiler, or you won’t be able to compile the Qt library. (Now that would be stupid, wouldn’t it?)

  2. [Optional] (I guess). Install Service Pack 1 of VS 2010.
    But beware: according to a friend, it might have some bugs still :/

  3. Install the Qt Visual Studio Add-In:
    http://qt.nokia.com/downloads/visual-studio-add-in

  4. Download the Qt source code as .zip from:
    http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.4.zip
  5. Download and install the following patch for VS 2010:
    http://support.microsoft.com/kb/2280741

  6. Extract the thingy from step 4 to some decent location like C:\Qt\4.7.4\
    Be sure the location has no spaces or special characters included.
    After this step, C:\Qt\4.7.4\ should contain a lot of folders.

  7. Add the folder from step 6 to your environment variables.
    Windows 7: Control Panel –> System –> Advanced System Settings –> Environment Variables
    Call it QTDIR.

  8. Open a Visual Studio Command Prompt.

  9. Make your way by cd’ing to the folder from step 6.
  10. It seems that 4.8.0 needs Perl to configure correctly. Install Strawberry Perl and everything should be fine. (Only for 4.8.0, not for previous versions like 4.7.3 etc.)

  11. Run the following command:
    ”configure -debug-and-release -opensource -shared -no-qt3support -qt-sql-sqlite -phonon -phonon-backend -no-webkit -no-script -platform win32-msvc2010”

    Explanation:
    -debug-and-release: … if you don’t know what this means, please stop reading now.
    -opensource: install open source edition of Qt.
    -shared: makes the Qt libraries shared.
    -no-qt3support: sorry my retro friends, don’t like old code.
    -qt-sql-sqlite: enable support for the sqlite driver.
    -phonon: compile the Phonon module (some multimedia thingy of Qt).
    -phonon-backend: compile the platform-specific Phonon backend-plugin.
    -no-webkit: disable WebKit module (heard of some bugs in combination with VS, just to be safe and since I don’t need it).
    -no-script: same as no-webkit.
    -platform win32-msvc2010: build for VS 2010! (Don't try win64, does not work)
  1. Skip reading and press “y”.

  2. Wait while Qt is getting configured for your platform.

  3. When done, run “nmake” to start compiling Qt.

  4. Wait again, long this time.
  5. When it’s done (few warnings, no errors on my side) open Visual Studio 2010. Go to Qt –> Qt Options and add the folder from step 6.

  6. Create a new Qt project (or open a .pro project). Should work flawlessly!
So that’s how I got it working here. I wish you all the best of luck on your Qt + VS 2010 adventures!

Feel free to share this tutorial by linking to this post, not copy+pasting the content.
Else I will be forced to get my friend Mathy to trace your IP and let your PC explode in your face.
See you all later,
Thomas
P.S.: This tutorial was originally written for Qt 4.7.2, but should also work with 4.7.3, 4.7.4 and 4.8!