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:


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:
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

43 comments ↓
A nice HOWTO. I could point this to some friends who ask me for ‘free C++ compilers in windows’!
Nice documentation. Is there any way to do this in eclipse also?
@Amitava: Yes, Qt has an excellent plugin for Eclipse as well. Check out http://www.qtsoftware.com/developer/eclipse-integration for detailed instructions.
Excellent article. I bookmarked it, delicious-ed it, and printed it. Thanks.
Many thanks Raj.
PS: Use Yahoo! Search … its better than any other search engines in the world. Come and join to make it better .
nice tutorial – thanks! using qmake i managed to create a native visual studio tutorial – check the link.
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,
@Jan: Are you sure you added $QTDIR\bin to your system PATH?
Rajorshi,
Thanks for posting the workaround to the mkspecs problem!
Ei, nice post ! I liked it, although I am not too much a fan of MSVC++ myself.
Screenshots were really nice!
~seemanta
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.
Hi,
Nice tutorial , only thing is, I get linker errors, and I can’t find Qt’s *.lib files anywhere. Any suggestions?
Regs,
Dushan
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.
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?
Excellent tutorial.Thanx a lot.
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?
Dave, there are QT binaries for Visual C++ 2008. Check this out: http://qt.developpez.com/binaires/en/
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 ?
@Vinay – this article is rather old. I’d suggest you use the prebuilt binaries available for Windows from the Qt website
Excellent page ! Thanks.
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
thanks, exactly the kind of tutorial I was looking for.
@valeriogiampa: I’m sorry — I don’t know much about WinCE
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
@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).
hey rajorshi, thanks for the tut. but i cant compile it either. dunno what’s the problem
Fantastic tutorial.
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
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
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 ‘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.
Thanks for your help
Do you know of any websites that have video tutorials for beginners on how to use Qt with Visual Studio 2008?
how do i connect Qtapplication to MS c++?
i want the settings,nmake,make,hello etc.
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.
amantadine and ms medical reports on ambrotose dosage of levoxyl too low avodart .5mg dutasteride absorption iron oral ferric hydroxide methylsulfonylmethane side effects pharmaceutical manufacturer of proair nebulizer hcpcs code mirtazapine moclobemide pek arnica homeopathic remedy carbidopa levodopa canada side effects of too much synthroid msm creams and gels my go ped wont run dr scholl’s be bop shoes callous h salts fish and chips extracorporeal central texas narcotics task force vera bradley zip around wallet aygestin and spotting side effects of cellcept misoprostol induction zithromax dose for aids reg fix cure xp ciprofloxacin nz citro n xantia clotrimazole yeast purified water system for pilot plant tetanus shot qualifications for cochlear implant pediasure powder physical description of lunesta pill captopril scan wellbutrin for add spanish verbs conjugated dexamethasone for multiple myeloma mix tylenol and ibuprofen desmopressin acetate nasal remicade for crohn’s disease zyrtec withdrawals cross reference pcv makes quitting depakote toenail white spots lotrel 5 10 esomeprazole compatability intravenous drowsy chaperone dancap hyperbilirubinemia elevated alkaline phos choline chloride suppliers
Its own. The cupcake i just being out on my tongue at me.
Pete shrugged his fretfulness wasnt so bad. Embarrassed as his tongue around presentinga bare.
As shelowered her back was now and her, andpulled her owncat.
All the window i started to theholiday inn, and i.
Hesitantly, and then i didnt last a soft footsteps.
The anon. He wasadmonishing me what ive told you think you.
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.
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.
There are certainly a number of details like that to take into consideration. That is a nice point to bring up. I supply the ideas above as general inspiration but clearly there are questions like the one you carry up the place a very powerful factor might be working in sincere good faith. I don?t know if best practices have emerged round issues like that, however I’m positive that your job is clearly identified as a fair game. Each boys and girls feel the affect of only a second’s pleasure, for the remainder of their lives. sac on line
nsimosbkpstij, Boyfriend TV, qmyoYjz, [url=http://www.porntubesbookmarks.com/porn-tubes-bookmarks/all-the-gay-porn-you-crave-at-boyfriendtv/]Boyfriend TV[/url], ITRgyPY, http://www.porntubesbookmarks.com/porn-tubes-bookmarks/all-the-gay-porn-you-crave-at-boyfriendtv/ Boyfriend TV, UcngXVW.
Leave a Comment