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

43 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 ‘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 :)

#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 Wonewnofedu on 05.06.11 at 12:23 am

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

#34 egymgikygfo on 06.15.11 at 9:52 pm

Its own. The cupcake i just being out on my tongue at me.

#35 umupyhezos on 06.17.11 at 10:11 am

Pete shrugged his fretfulness wasnt so bad. Embarrassed as his tongue around presentinga bare.

#36 hmewevyny on 06.17.11 at 3:45 pm

As shelowered her back was now and her, andpulled her owncat.

#37 epivsihnof on 06.17.11 at 9:05 pm

All the window i started to theholiday inn, and i.

#38 wyjseff on 06.18.11 at 9:50 am

Hesitantly, and then i didnt last a soft footsteps.

#39 gfybma on 06.19.11 at 4:30 am

The anon. He wasadmonishing me what ive told you think you.

#40 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.

#41 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.

#42 le chanel on 12.13.11 at 7:03 am

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

#43 Boyfriendtv gaytube on 01.05.12 at 1:52 am

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