How to: Setup Qt 4.5+ Visual Studio Integration

(NOTE:  This post was originally published on Mar 06, 2009.  It was subsequently moved to the wordpress.com blog service and updated reflect the many comments.  Thank you for contributing your comments!

QT IS NOW RELEASED UNDER LPGL

Qt is a cross platform GUI toolkit which was acquired from Trolltech by Nokia.  Starting with Qt 4.5, it is dual-licensed under both LPGL and Commercial.  The Commercial license can be a bit pricey, but the LPGL license means you can use it free of charge to develop proprietary, commercial, closed-source software.  Instantly, Qt has become available to a wide audience of software developers (DCSoft included).  Thank you Nokia!

More than a year ago, DCSoft has become very interested in Qt.  Much as we love MFC, it hasn’t changed much since 1999, and this is 2009.  Qt is easy to learn given its concise syntax and documentation, plugs into Visual Studio (more below), comes with a supported toolset including Designer (a resource editor), Linguist (a localization tool), and Qt Creator (an IDE), giving Qt more momentum than MFC, and a higher performance alternative to .NET.  It’s easily one of the best ways to create Windows apps, never mind it can also target Mac, Linux, and several embedded devices.

Starting with Qt 4.6, the LPGL version now comes pre-built for Visual Studio 2008 RTM.  If this fits your need, you can simply install it and skip to INSTALL VISUAL STUDIO ADD-IN. However, you will need to build Qt yourself if:

  1. You are using VS 2008 and you have installed SP1 and/or the ATL Security Update, and you are building your app with the _BIND_TO_CURRENT_VCLIBS_VERSION defined (or another means to specify the non-RTM version).  This is because both Qt and your app need to be built with the same version of the Visual Studio redistributables, and Qt has been built with RTM, but your app is not being built with RTM.
  2. You are using any version of VS 2005.  This is because Qt does not come prebuilt for VS 2005.

Here’s how to get our favorite IDE (Visual Studio 2005/2008) working with Qt!

DOWNLOAD QT SOURCE CODE

As the option to download only the Qt source code is a bit obfuscated on the current Nokia website, please follow these directions:

  1. Go to http://qt.nokia.com/downloads and click the Go LGPL button.
  2. Since you want only source code, look at the Qt: Framework Only column on the right.  Click e.g. Download Qt libraries 4.6.1 for Windows (VS 2008, 194 MB) — choose the VS2008 one.
  3. This starts the download for pre-built Qt.  But we don’t want that as we will be building Qt ourselves.  A page will appear with <Source code available on this link>.  Cancel the Save As dialog in your browser to cancel the binaries download you had clicked on, then click on this link, e.g. http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.6.1.zip
  4. Unzip the file into e.g. c:\qt\4.6.1-vc.  Please use a path with no embedded spaces, as the Qt build tools have issues with them.

SET ENVIRONMENT VARIABLES

Open Computer Properties | Advanced system settings | Environment Variables:

  1. Edit environment variable to add:  QTDIR = c:\qt\4.6.1-vc
  2. Edit the PATH environment variable to add:  %QTDIR%\bin
  3. Either close all command prompts and Visual Studio instances, or reboot the computer so the new command-line takes effect.

BUILD VC++ VERSION OF QT

  1. Open a Microsoft Visual Studio Command Prompt, which is a command console with environment variables set for the specified VS.  This is easily accomplished using Start | All Programs | Microsoft Visual Studio 2005 (or 2008) | Visual Studio Tools | Visual Studio 2005 (or 2008) Command Prompt.
  2. Cleanup any previous build:
    1. c:\> cd c:\qt\4.6.1-vc
    2. c:\qt\4.6.1-vc> nmake distclean
    3. c:\qt\4.6.1-vc> rm -rf tmp*  // <– recursively remove all tmp\ folders and files

This requires finding a *nix workalike.  I use Total Commander to search for Tmp*, select all the found files, and delete them with one keystroke.

3. Run Configure to target platform vc2005 or vc2008:

c:\qt\4.6.1-vc> configure -platform win32-msvc2005 <other options as needed>

Substitute win32-msvc2008 for VC2008

Run Configure with no parameters to see a help screen.  Configure generates nmake compatible makefiles to build all the Qt DLL’s, tools, and demos.

4.  Run nmake to build.

c:\qt\4.6.1-vc> nmake

It will take awhile, but this grinds through building the specified Qt DLL’s, tools, and demos with Visual Studio.

INSTALL VISUAL STUDIO ADD-IN

The Qt Visual Studio Add-in is indispensible for developing Qt apps in Visual Studio. The Add-in has replaced the previous Qt Visual Studio Integration, which was only available to Commercial customers.  Now the Add-in is used by both LPGL and Commercial licensees, and the Integration has been deprecated.  While the Add-in does not allow integrated .ui editing (it instead launches Qt Designer to edit .ui files), it is fully supported and maintained by Nokia, whereas the Integration hadn’t been modified since the 4.3/4.4 timeframe.

Because Visual Studio Express does not allow add-ins, using these free versions of Visual Studio is not recommended for Qt development.  You need at least Visual Studio Standard (Pro, Team System, etc. of course will also work).

1.  Download and install the Qt Visual Studio Add-in to install the Qt plug-in into Visual Studio (both 2005 and 2008 are supported by the add-in).

2.  Start Visual Studio.

3.  Select menu Qt | Configure Qt Versions.  Add c:\qt\4.6.1-vc.

4.  Now Qt is fully functional, and you can use VS2005/2008 to build Qt apps.

QT IN VISUAL STUDIO

1.  See Qt menu item.  Launch Qt Designer (the Resource editor) and Qt Linguist (the localization tool).

2.  Create new Qt projects.  File | New project, select Qt4 project.

3.  Read Qt Help.  Available from Help menu (Qt help is merged in with Visual Studio Help and viewed in Document Explorer.)  Or, manually launch

C:\Qt\4.6.1-vc\bin\assistant.exe

4.  The Whole Tomato Visual Assist X plug-in is highly recommended to develop Qt within Visual Studio.  See this blog entry for tips.

About these ads

15 Responses to “How to: Setup Qt 4.5+ Visual Studio Integration”

  1. TheRohan Says:

    hi all,
    Thanks for the detailed story. That was really informative however also wanted to add about the new Qt hybrid application which demonstrates how to use the QtWebKit module to display web content in Qt.

    Check this:

    http://www.forum.nokia.com/info/sw.nokia.com/id/f12cce87-430e-49b0-81b1-0ec1b07cdb1c/QtWebKit_Beta_Labs_Example.html

  2. Bibac Says:

    it’s not working. when i try to configure i get a lot of “could not find …” messages and it quits by returning 2.

  3. Richard Stellingwerff Says:

    There is one problem with Qt 4.6.2 prebuilt for vs2008. The plugins (qjpeg4.dll for sure) are linked against msvcr80.dll, while the QtCore and other libraries are linked against msvcr90.dll. I believe this is the cause of various R6043 errors I’ve been getting on system that I’ve deployed my app on.

  4. Mustafa AZAK Says:

    I have Qt 4.6.2. Add-in does not work properly with Visual Studio 2005. I could not start the Qt Designer.
    Method not found: ‘Boolean.System.Threading.WaitHandle.WaitOne(Int32)
    Stack Trace:
    at Qt4VSAddin.ExtLoader.loadDesigner(String filename)
    at Qt4VSAddin.Connect.Exec(String commandName, vsCommandExecOption,Object& varIn,Object& varOut, Boolean& handled)

    Any suggestions?

    Thank you very much.

  5. Rajendra Says:

    I Installed QT 4.6.2, VS2008 Prof on Vista Ultimae. Qt Designer displaying same message when started from withing VS2008 QT Menu.
    Solution:
    I Downloaded VS2008 SP1 from Microsoft website (ISO File) and Installed.
    Now Qt Designer is working properly.

  6. rajendra Says:

    I installed QT 4.6.1 on VS2005, with XP SP2.
    QT degined was not working from wthing VS2005 and VS2008 environment QT Menu.
    Then I installed MS .NET FrameWork 3.5 SP1.
    This solved the problem of
    Method not found: ‘Boolean.System.Threading.WaitHandle.WaitOne(Int32)
    Stack Trace:
    at Qt4VSAddin.ExtLoader.loadDesigner(String filename)
    at Qt4VSAddin.Connect.Exec(String commandName, vsCommandExecOption,Object& varIn,Object& varOut, Boolean& handled)

    Now Qt Desinged Working Properly with VS205 & VS2008 on same Machine.

  7. 网络寻租 » Blog Archive » 如何在windows环境下使用visual studio 2008开发qt Says:

    [...] 引用: http://doc.trolltech.com/4.6/install-win.html http://dcsoft.wordpress.com/2010/01/30/how-to-setup-qt-4-5-visual-studio-integration/ [...]

  8. Michael Says:

    Hi Guys,

    Am i need to build the qt stuff, or can i only install the add-in?
    I’ll use qt 4.7 with VS2005.

    Greets,
    Michael

  9. Michael Says:

    I found this article by searching for Visual Studio 2010 and all about this damn article is about 2008 -> OLD -> NOT INTERESTING

  10. azg Says:

    Is it possible to use the documentation that qt provides directly in visual studio? Something like F1 is doing in qt creator ?

    Thanks

  11. blogger wordpress Says:

    blogger wordpress…

    [...]How to: Setup Qt 4.5+ Visual Studio Integration « DCSoft blog[...]…

  12. student Says:

    When i run the command nmake, it’s taking very long…. it’s past 12 hrs and is still running… is it supposed to be taking this lot of tym??

  13. How to create Paraview MVS solution using CMake | Alexis' Blog Says:

    [...] You should build Qt using the same compiler you are going to use to build Paraview. (I used Qt 4.7 with Microsoft Visual Studio 2008. You can follow the steps here for installing Qt: [2]) [...]

  14. Margo Says:

    “How to: Setup Qt 4.5+ Visual Studio Integration | DCSoft blog” lachristiesgreatestates seriously got me personally hooked with
    your site! Idefinitely will be back again much more normally.

    Thank you ,Merrill

  15. Johng551 Says:

    I do trust all of the ideas you’ve presented in your post. They’re very convincing and can certainly work. Nonetheless, the posts are very short for beginners. May just you please lengthen them a bit from next time? Thanks for the post. ggeebdacfkkc

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: