Using Qt 4.4 opensource with Microsoft Visual C++ Express 2008

Qt from Trolltech is widely acknowledged as one of the best cross-platform GUI toolkits available. However, installing the Qt open source edition on Windows is not as effortless as “sudo apt-get install qt” on Ubuntu or other Linux flavors. It’s not that hard either, and this post shows you how to develop using the freely available Microsoft Visual C++ 2008 Express as our IDE.

1. I’m assuming you have MSVC 2008 Express already installed. If not, download the offline install ISO from here, mount it (using Daemon Tools for example), and launch the installer from the virtual drive.  Next, download the Windows open source version of Qt from here.

2. Now, you can either extract the Qt source package to a folder where you want it to be installed, or you might want to extract it to a temporary location, and install only the final files to your install directory. Doing the latter of course makes more sense. Except that it is NOT recommended for Windows. I have faced quite a few problems (which I will detail further down the line). Bottom line is – if you have no problems sparing about 1G for Qt, then choose the former approach.

Open up the “Visual Studio 2008 Command Prompt” (available in the “Tools” sub-menu in your Visual C++ start menu entry). For the former approach, issue the following command:

configure

If you want a separate install directory (let’s say in D:\Qt-4.4.3), use the ‘prefix’ flag in this manner:

configure -prefix "D:\Qt-4.4.3"

3. Depending on your system, this takes a quite a while. Oh, and if you face an error like this, fear not:

copy qmake.exe P:\qt-win-opensource-src-4.4.3\bin\qmake.exe
        1 file(s) copied.
Creating makefiles in src...
Generating Visual Studio project files...
Could not find mkspecs for your QMAKESPEC(win32-msvc2008)
after trying:
        D:\Qt-4.4.3\mkspecs
Error processing project file:
P:/qt-win-opensource-src-4.4.3/projects.pro
Qmake failed, return code 3

This is the first of a few problems that crop up when you use a custom install location (i.e. the latter approach). Just copy the “mkspecs” folder from your source directory tree over to your install directory and re-run the configure program.

4. Once ‘configure’ completes, run ‘nmake’. This takes a really long time. If you chose to have a separate install location, run ‘nmake install’ once this completes.

5. Another problem of a separate install directory is that the Makefile forgets to copy the MANIFEST files. So, if at this stage you try to start “designer.exe” from your install/bin folder, you may get an error saying that the application failed to start because MSVCP90.dll was not found.

To fix this, copy over all the “.manifest” files from your source “bin” and “lib” directories over to the install folder’s “bin” and “lib” directories. At this point, you should be able to run Qt-Designer, Qt-Assistant etc from your bin directory.

6. Let us set up a couple of environment variables that make life easier for us. To edit environment variables, you need to right click “My Computer > Properties > Advanced > Environment Variables”. Add a new variable QTDIR pointing to your Qt install directory, and edit your PATH to include Qt’s “bin” directory as follows:

Setting QTDIR

Adding to PATH

 

7. Now let’s try to get Qt’s “Hello World” tutorial program running from the command line. Fire up the Visual Studio Command Prompt, and create a file “Hello.cpp” containing the following code in a new directory called “hello”:


#include "QApplication"
#include "QPushButton"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QPushButton hello("Hello world");
    hello.resize(100, 30);

    hello.show();
    return app.exec();
}

Now, type the following commands in this new folder:

qmake -project
qmake hello.pro
nmake

This should create an executable “hello.exe”, which you should be able to execute to see your first GUI program using Qt-4.4 and MSVC 2008.

7. I would suggest working from the command prompt, but should you wish to use the Visual Studio Express IDE, here’s what you should do.

Fire it up, and go to “Tools > Options > Projects and Solutions > VC++ Directories”. Add “$(QTDIR)\include” to the “Include files”, and “$(QTDIR)\lib” to the “Library files” drop-down lists respectively.

8. Create a new project (“File > New > Project > General > Makefile Project”) named “HelloQt”.

Go to “Project > Properties > Configuration Properties > Nmake” and enter the following in the build command line “qmake -project && qmake && nmake release-all”. Also enter “release\HelloQt.exe” in the “Output” field. (You may enter corresponding debug versions here as well).

Right click “Source Files” in the “Solution Explorer” and create a new file “HelloQt.cpp”. Copy paste the above program into it.

Run your program using “Ctrl+F5″. You should see this:


Sample Qt 4.4 program running inside Microsoft Visual C++ Express 2008

So there you have it. A crash HOWTO on developing Qt-4.4 programs using Visual Studio 2008 express. Feel free do comment on any problems you may have faced.

~Raj

52 comments ↓

#1 Sujai on 01.18.09 at 12:54 pm

A nice HOWTO. I could point this to some friends who ask me for ‘free C++ compilers in windows’!

#2 Amitava on 01.23.09 at 5:17 pm

Nice documentation. Is there any way to do this in eclipse also?

#3 rajorshi on 01.23.09 at 8:50 pm

@Amitava: Yes, Qt has an excellent plugin for Eclipse as well. Check out http://www.qtsoftware.com/developer/eclipse-integration for detailed instructions.

#4 fernaco on 02.04.09 at 7:15 pm

Excellent article. I bookmarked it, delicious-ed it, and printed it. Thanks.

#5 Amitava on 02.14.09 at 12:57 pm

Many thanks Raj.
PS: Use Yahoo! Search … its better than any other search engines in the world. Come and join to make it better .

#6 ivan on 02.17.09 at 4:39 am

nice tutorial – thanks! using qmake i managed to create a native visual studio tutorial – check the link.

#7 Jan on 02.26.09 at 4:33 pm

Yes, nice, I followed instructions to detail, but it does not work for me in VCExpress2008, as VCE error is: ‘qmake’ is not recognized as an internal or external command,

#8 rajorshi on 02.26.09 at 9:22 pm

@Jan: Are you sure you added $QTDIR\bin to your system PATH?

#9 Jon on 02.28.09 at 1:44 am

Rajorshi,
Thanks for posting the workaround to the mkspecs problem!

#10 Seemanta on 03.03.09 at 1:09 am

Ei, nice post ! I liked it, although I am not too much a fan of MSVC++ myself.

Screenshots were really nice!

~seemanta

#11 dude on 03.04.09 at 12:16 am

excellent article. Thank you! I am loving the new qt 4.5 license, now I don’t worry about that and drop wxwidgets, which I was only using a little bit. Now if I can only convince them to use it at work and drop codegear for guis.

#12 Dule on 03.06.09 at 8:39 pm

Hi,
Nice tutorial , only thing is, I get linker errors, and I can’t find Qt’s *.lib files anywhere. Any suggestions? :)

Regs,
Dushan

#13 Jon on 04.25.09 at 4:00 pm

Dule,

I don’t know what to make of this tutorial/article.

You need to compile Qt 4.5 src to get the .lib library files. VS doesn’t use the .a library files.

I found an article somewhere online that mentions all that, straight from Trolltech’s on wiki, I think. Forgot where it is now.

#14 paul on 06.13.09 at 12:51 pm

when I type qmake -project I keep getting an error message:

Error processing meta file: c:\Qt\4.5.1\lib\qtmain
Error processing meta file: c:\Qt\4.5.1\lib\qtmaind
Error processing meta file: C:\Qt\4.5.1\lib\qtmain

whats wrong?

#15 channa on 10.05.09 at 11:58 am

Excellent tutorial.Thanx a lot.

#16 Dave on 10.19.09 at 2:22 am

It would appear that Qt is not available in binary form pre-built for Visual C++ 2008. Thus compiling from source by hand is the only option for LGPL/VC2008. Is that correct?

#17 Daniel Lewandowski on 10.21.09 at 2:12 pm

Dave, there are QT binaries for Visual C++ 2008. Check this out: http://qt.developpez.com/binaires/en/

#18 Vinay on 11.06.09 at 9:49 am

Thanks for this article. I have a question though. You mention that we should run “configure”. I don’t seem to find this command anywhere. I installed QT for windows using the installer that comes with the download. Is that all the configure you mention is doing ?

#19 rajorshi on 11.15.09 at 6:58 pm

@Vinay – this article is rather old. I’d suggest you use the prebuilt binaries available for Windows from the Qt website

#20 Carmen Ramos on 03.03.10 at 1:50 am

Excellent page ! Thanks.

#21 valeriogiampa on 05.05.10 at 9:05 pm

Dear ~Raj and all reader of this best tutorial,
I have a problem.
in the internet there are more tutorial to use and integrate QT with Visual Studio 2005/2008 or Express/Professional and I have tested it becouse I must configure a Personal Computer with QT SDK to develop application for Symbian, Linux, Windows and WinCe.
With Symbian I have obtained a goal, for windows the command line that ~Raj have wroten in this tutorial can delivery the exe, but I have problem to generate and run the debug session for WinCe.
Can ~Raj or the other reader help me for this problem?
Thanks.

valeriogiampa
valeriogiampa@inwind.it

#22 larry_the_lame on 05.18.10 at 7:47 pm

thanks, exactly the kind of tutorial I was looking for.

#23 rajorshi on 06.05.10 at 7:15 pm

@valeriogiampa: I’m sorry — I don’t know much about WinCE :-(

#24 johnnyturbo3 on 07.30.10 at 2:28 pm

Hi,

Thanks for this tutorial, it’s been a great help to me.

Qt works – but I get a message when I compile and debug:

“Debug information for ‘Hello.exe’ cannot be found or does not match. Binary was not built with debug information.”

It then asks whether to carry on, and everything runs fine.

I was wondering if this may become a problem further down the line?

Thanks

#25 rajorshi on 07.31.10 at 6:37 pm

@johnnyturbo3 – that just means you won’t be able to debug your binary. It’s not a problem at all. If you would like to include debugging symbols, be sure to include the appropriate flags to your compiler (‘/Zi’ etc).

#26 jack on 08.02.10 at 1:50 pm

hey rajorshi, thanks for the tut. but i cant compile it either. dunno what’s the problem :(

#27 dusty on 08.11.10 at 4:35 am

Fantastic tutorial. :D

I read that *.dlls could only be linked to Qt if compiled in the proper compiler ie. GCC *.dll for GCC compiler etc. This makes life a lot easier for windows users making use of native *.dlls.

Nice tip for setting the correct build command line. I just couldn’t get that bit working.

(Noob and proud of it… we all start somewhere ;)

#28 plz guide me on 08.17.10 at 7:41 pm

sir

i want to know how to use gmp in c prog to implement rsa algo.

i .e. instalation procedure or copying files in windows plotform

plz reply soon sir
waiting for ur reply

#29 ZiKaS on 09.23.10 at 1:31 am

Thanks for this useful post! I’ve faced this error after running nmake:
link /LIBPATH:”c:\Qt\4.7.0\src\tools\bootstrap\release” /NOLOGO /INCREME
NTAL:NO /SUBSYSTEM:CONSOLE /MANIFEST /MANIFESTFILE:”release\moc.intermediate.man
ifest” /OUT:..\..\..\bin\moc.exe @C:\DOCUME~1\ABDELR~1\LOCALS~1\Temp\nm23A.tmp
LINK : fatal error LNK1181: cannot open input file ‘zdll.lib’
NMAKE : fatal error U1077: ‘”C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
\link.EXE”‘ : return code ’0x49d’
Stop.
NMAKE : fatal error U1077: ‘”C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
\nmake.exe”‘ : return code ’0×2′
Stop.
NMAKE : fatal error U1077: ‘cd’ : return code ’0×2′
Stop.

Thanks for your help :)

#30 Chris on 03.06.11 at 10:45 pm

Do you know of any websites that have video tutorials for beginners on how to use Qt with Visual Studio 2008?

#31 Macco on 04.06.11 at 5:14 pm

how do i connect Qtapplication to MS c++?
i want the settings,nmake,make,hello etc.

#32 Cherub on 04.16.11 at 2:59 pm

Thanks a lot for the post!!

That nmake step took around 3hrs & finally it showed this error msgs to the end ->

NMAKE : fatal error U1077: ‘”C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
\link.EXE”‘ : return code ‘0×49d’
Stop.
NMAKE : fatal error U1077: ‘”C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
\nmake.exe”‘ : return code ‘0×2?
Stop.
NMAKE : fatal error U1077: ‘cd’ : return code ‘0×2?
Stop.

But still I proceeded further & voila!! it worked.. I was able to run the HelloQt project in VS IDE also.
Thanks a ton again.

#33 Jacob on 07.30.11 at 1:30 am

could someone please let me know how to do the following:

how do you link static libraries (.lib) files into qt. this howto makefile project doesn’t allow you to link .lib files.

any suggestion would be greatly appreciated.

#34 Muhammad Shahid on 10.13.11 at 4:05 pm

Today I downloaded the latest Qt version from qt.nokia.com/downloads/.
I did not download Qt SDK that is used with minGW, because I wanted to compile the code with MS VC++ 2008 Express. Here are the steps I did get to make Qt compatible with VC++ 2008 Express.

1. First I installed VC++ 2008 Express SP1.
2. I downloaded the version that reads “Qt libraries 4.7.4 for Windows(VS 2008, 228MB)” from qt.nokia.com/downloads/
5. I installed the application to G:\Qt\
6. After installing I did find “Qt 4.7.4 Command Prompt” and click it.
7. This did set the required variables for building Qt applications with VC++ 2008 Express.
8. I write a basic Qt application and put it into G:\Qt\Hello Qt\. Your may differ!
9. I again did open “Qt 4.7.4 Command Prompt” and called directory “Hello Qt” with “cd Hello Qt” command.
10. I did write this command to make a project file for my Qt app. “qmake -project”.
11. I did write this command to compile my project file. “nmake release”. The application did get compiled just fine.
12. I did try to run the exe file but find that essential Qt dll files “QtGui4.dll, QtCore.dll” was not found.
13. I simply copy them from Qt bin folder to the “Hello Qt\release” folder.
14. The application worked just fine.

please do it yourself, it will work!

Thanks!

Muhammad Shahid.

#35 Google Places Optimization on 05.11.12 at 5:19 pm

Hi I like your blog site. Do you need to guest post on my own sometime? If that’s the case please tell me by means of e mail or simply answer this remark since My partner and my spouse and i actually enrolled in notices and definately will realize should you choose.

#36 Edwardo Schenewerk on 05.11.12 at 8:41 pm

Woah! I’m truly digging the actual template/theme of this blog. It’s simple, yet successful. A large amount of times it is rather hard to get that perfect balance between functionality and visual appeal. I need to say you have done a good job with this. In addition, the web site loads extremely swift for myself on Opera. Excellent Website!

#37 Antonietta Goude on 05.12.12 at 9:44 am

Amazing excellent breakdown presently there, your running a blog site article had been actually beneficial. You have to think about growing to be a instructor or even anything, whatever you simply described over is pretty elaborate but even a 2nd grader could have comprehended it.

#38 Glenda Rives on 05.12.12 at 11:38 am

Hello, i feel that i discovered you went to my weblog and so i got here to go back the favor. I am looking for things to further improve my web site! I assume its ok to work with a few of your concepts!!

#39 grammar site on 05.12.12 at 1:55 pm

I not to mention my pals have already been looking through the great helpful hints located on the blog and quickly I got an awful suspicion I never expressed respect to the website owner for them. All the young men are already totally excited to read all of them and have now surely been tapping into these things. Appreciate your being indeed considerate as well as for obtaining this kind of cool topics most people are really eager to discover. My honest apologies for not expressing appreciation to sooner.

#40 Claudio Honn on 05.13.12 at 5:52 am

Merely wanna comment that you have a very decent internet site , I the layout it actually stands out.

#41 Costa Rica Vacation on 05.15.12 at 1:15 pm

Superior content on the other hand Let me notify you that I think there is trouble with your RSS feeds when they seem to not be working for me. Might be just me but I figured I would discuss it.

#42 Diablo 3 Information on 05.15.12 at 5:24 pm

Thank you, this can be the worst thing I’ve study

#43 Lee Edwads on 05.15.12 at 8:57 pm

Good website! I really love how it is simple on my eyes and the data are well crafted. I are wondering how i might become notified whenever a new post has been made. I’ve subscribed in your feed that must do the trick! Have an excellent day!

#44 Teresita Lyde on 05.16.12 at 1:32 am

Like any medicine, ixiaro could ti negative effects, but the actual mezcle involving antioxidant bativan use/b statistics is formally low.

#45 More information on 05.16.12 at 10:47 pm

Excellent web site. Lots of useful information here. I’m sending it to several pals ans also sharing in delicious. And of course, thanks to your sweat!

#46 tricare express pharmacy on 05.17.12 at 7:53 am

I mastered more interesting things on this weight-loss issue. One particular issue is that good nutrition is tremendously vital whenever dieting. A huge reduction in junk food, sugary foodstuff, fried foods, sweet foods, beef, and white flour products could possibly be necessary. Retaining wastes harmful bacteria, and wastes may prevent desired goals for fat-loss. While particular drugs briefly solve the challenge, the horrible side effects are not worth it, and so they never give more than a temporary solution. It can be a known incontrovertible fact that 95% of celebrity diets fail. Many thanks sharing your notions on this blog site.

#47 residence roma on 05.17.12 at 5:51 pm

Thanks – Enjoyed this article, how can I make is so that I get an alert email every time there is a fresh article?

#48 Lory Lanagan on 05.17.12 at 6:03 pm

A several months ago my spouse and i book marked your blog and have returned on several times to catch up with some of your respective articles on the other hand until right now I certainly not commented that i think is often a shame since comments can occasionally help assist this article writer. I adore blogs with great content and several of your own articles are actually well presented nevertheless the feedback left from your readers are usually fantastic and several made us laugh although I have to be truthful you’ll find comments in which mystified me regarding point or even the link with the major write-up although most likely they made sense on the original poster. Like oneself I run my own blog, with the hope that it might improve contact with my principal company, however unlike your site i struggle to win readers and quite a few content put up onto our site receive essentially 2 comments which makes it not an easy task to continue with such tiny return. I realize that my styles are maybe less attention-grabbing than your with many based on Waste Removal and Recycling however I sooo want to push the particular audience increased. I wish this does not appear as being a cheeky ask for, however I was hoping that you might spare me somewhat with respect to dropping us an e-mail along with any advice that may improve us raise my blogs exposure as without having readers blogging can be quite a lonely activity.

#49 Kendall Vanhoesen on 05.18.12 at 1:41 am

I simply wanted to write down a simple word to thank you for these pleasant ways you are posting at this website. My time intensive internet lookup has at the end of the day been paid with extremely good details to exchange with my two friends. I ‘d believe that we website visitors actually are undoubtedly lucky to be in a great network with so many special individuals with beneficial concepts. I feel somewhat fortunate to have discovered your entire webpages and look forward to some more exciting minutes reading here. Thanks a lot once more for all the details.

#50 properties in Costa Rica on 05.19.12 at 4:14 am

Great information on the other hand I would like to tell you that I think there is issue with your RSS feeds as they seem to not be working for me. Could possibly be just me but I figured I would discuss it.

#51 Brochure Design on 05.19.12 at 12:33 pm

That is the precise weblog for anyone who wants to find out about this topic. You realize so much its virtually onerous to argue with you (not that I truly would need…HaHa). You undoubtedly put a brand new spin on a subject thats been written about for years. Nice stuff, simply great!

#52 Jesse Guthary on 05.19.12 at 7:35 pm

The very next time I read a blog, I hope that it does not fail me as much as this particular one. After all, I know it was my choice to read through, but I genuinely believed you’d have something interesting to talk about. All I hear is a bunch of complaining about something you could fix if you weren’t too busy seeking attention.

Leave a Comment