Qt 4.3 with Visual Studio 2008

First of all, the title is inaccurate. This post is about how to install Qt 4.3 with visual studio 2008 Express edition (Visual c++ 9.0). The express edition of visual studio is a free and limited edition by Microsoft. Yeah… it came as a surprise to me too. Qt on the other hand, is a cross-platform API for programming Gui in your applications, by trolltec (those who use KDE should know about it).

The whole point here is that trolltec gives an open source edition of Qt for all platforms, but this open source edition cannot work with the professional editions of visual studio. And like me, some guys are really used in visual studio (in windows environment), and they don’t want to, or cannot use a different IDE. I, for example, was too bored to install and configure Code::blocks to work with all the other api i use.

So here’s a guide on how to compile qt4.3, and make it work with visual studio 2008.

Step 1:

Grab the open source edition of Qt for windows from trolltec.

If you don’t have visual studio express 2008, download it here. It’s an iso file around 900 mb, if I remember right. You can always do a web install of VC++ if you don’t want to download the whole studio.

Step 2:

Extract qt to a directory (i used C:/Qt4.3). its better not to extract it in a directory with spaces in it’s name.

Now open the visual studio console (programm files->visual studio 2008-> vs 2008 tools-> vs 2008 command promt). Go to the directory where you unzipped qt and type configure.

step3.png

And now you are ready for the long long part. Type nmake. Go grab a cup of coffee, take a walk, do whatever you want, because this part usually takes from 2 to 4 hours. Depends on your pc, of course.

Step 3:

step4.png

So now that the boring part is over, right click on “My Computer”->properties->advanced->environment variables and add QTDIR = c:/Qt4.3 (or whatever your qt dir is), edit the path variable to add ;%QTDIR%/bin

Step 4: Almost there

Now that we’ve compiled qt and configured the enviromental variables, we need to configure visual C++, so it can see Qt.

go to your VC++ options (tools->options) and add:

$(QTDIR)/include to the include directories
and
$(QTDIR)/lib to the lib directories

THE END

Now you are ready to program with Qt. Include the necessary libs and headers and start typing… Sometime soon (I hope 2-3 days) I’ll post a very basic application with Qt 4.3.4 and VC++ 9.0, just to show how easy it is to create a Gui application without needing to use the WinAPI.

  1. April 13th, 2008,  9:32 am

    [...] code要在Windows上安裝 還真是令人有點摸不著頭緒 還好在網路上翻到這篇 [...]

  2. By Fabian
    April 23rd, 2008,  5:08 am

    Hi there!
    Im so glad to find your homepage, I want to use Visual c++ 2009 Express and QT 4.3.4.
    Unlike you i installed QT via -qt-win-opensource-4.3.4-mingw.exe-
    I did the rest of your tutorial in exactly the same way as you.
    I tried to compile this small app:

    #include
    #include

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QPushButton hello(”Hello World!”);
    hello.resize(100, 30);
    QObject::connect(&hello, SIGNAL(clicked()),
    &app, SLOT(quit()));
    hello.show();
    return app.exec();
    }

    That workes, but afterwards I got a couple of linker errors:
    e.g.:
    —— Build started: Project: Test01, Configuration: Debug Win32 ——
    Linking…
    main.obj : error LNK2019: unresolved external symbol “__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)” (__imp_??1QApplication@@UAE@XZ) referenced in function _main

    do you have any advice?
    Thank you in advance..
    Fabian

  3. By  .v0id
    April 23rd, 2008,  4:57 pm

    You installed Qt on visual studio 2008 Express (VC++ 9.0) through the Qt windows installer? As far as I know, this Qt version works only if you have mingw compiler installed. If you want Qt to work with Visual C++, you have to compile Qt from the source.

    I’m not a really good programmer, but I think that this error means that your linker, cannot find or cannot use the Qt lib and dll files. Which means that either it cannot find your “$(QTDIR)/lib” folder, or it cannot use those lib and dll files since they are meant to be used only from mingw. I think that if you compile Qt from the source, you won’t have any problem compiling a qt application.

    My advice: Try compiling Qt from the source, using nmake.

    I hope I’ve helped.

  4. April 24th, 2008,  1:20 am

    .v0id is correct. You have to compile the binaries yourself to use Qt with visual studio express. I made a slightly more detailed guide to get started with Qt where I also show how to compile the example given by fabian. The guide is athttp://ankanet.org/index.php/tools/getting-started-with-other-ides. I made a bit more detailed instructions both of how to set up Qt with visual studio, as well as how to set up the example mentioned by fabian and an example of how to create your first application using Qt designer.

    The author mentions CodeBlocks as an IDE, but he should also have look at eclipse as Trolltech releases integrations to their libraries. If you use eclipse you can also install -qt-win-opensource-4.3.4-mingw.exe- as Fabian did.

    In some cases I prefer work with visual studio as well; but when it comes to Qt application i sometimes find it troublesome to maintain the .pro file and setting up the enviroment to compile as Qt every time I start a new Qt project.

    I made a similar guide to getting started with Qt in eclipse;http://ankanet.org/index.php/tools/getting-started-with-eclipse . If you compare the last chapters of how to create a Qt application with Qt designer you will notice you don’t have to write a single line of code or generate any profile inside eclipse. while you have to create a make file project, setting up the compiler to run qmake an nmake, creating pro file and classes to setup the ui generated file in visual studio. I am however impressed by the simplicity the author used to explain how to set up visual studio express.

    Enjoy your Qt programming!

    Kindly regards,

    Kent

  5. By Anna
    April 30th, 2008,  6:25 pm

    I’ve been trying to follow this, and the first time I tried, I didn’t think I had any errors, but Qt didn’t seem to be anywhere. I then tried the tutorial that Kent, above, wrote and I just got errors, and the compiling quit after about a minute. Every time I try something now, it appears to be mingw32-make that is prompted instead of nmake. I am using the Visual Studio command prompt, and I’ve tried cleaning it numerous times, but I have had no luck changing this. It does not compile with this compiler either. Does anyone have any suggestions on how I can overcome this? Below is a short read out from the prompt window right before it stops compiling. Thanks!

    #pragma warning
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:259: warning: ig
    noring
    #pragma warning
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:268: type
    specifier omitted for parameter `__int64′
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:268: parse
    error before `,’ token
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:269: ISO C++
    forbids declaration of `__int64′ with no type
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:269: warning: `
    __cdecl__’ attribute only applies to function types
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:269: conflicting

    types for `int __int64′
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdlib.h:779: previous
    declaration as `unsigned int __int64′
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:269: parse
    error before `(’ token
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: `push’ was

    not declared in this scope
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: `warning’
    was not declared in this scope
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: ISO C++
    forbids declaration of `__pragma’ with no type
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: `disable’
    was not declared in this scope
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: parse
    error before `:’ token
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: ISO C++
    forbids declaration of `__pragma’ with no type
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h: In function
    `int __pragma(…)’:
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: `int
    __pragma(…)’ redeclared as different kind of symbol
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: previous
    declaration of `int __pragma’
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: previous
    non-function declaration `int __pragma’
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: conflicts
    with function declaration `int __pragma(…)’
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h: In function
    `int _snprintf_s(char (&)[_Size], unsigned int, const char*, …)’:
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: `pop’
    undeclared (first use this function)
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: `warning’
    undeclared (first use this function)
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: ISO C++
    forbids declaration of `__pragma’ with no type
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: redefinitio
    n
    of `int __pragma’
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: `int
    __pragma’ previously defined here
    c:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/stdio.h:318: confused by
    earlier errors, bailing out
    mingw32-make[2]: *** [tmp/obj/debug_shared/qtmain_win.o] Error 1
    mingw32-make[2]: Leaving directory `C:/Qt/4.3/src/winmain’
    mingw32-make[1]: *** [debug-all] Error 2
    mingw32-make[1]: Leaving directory `C:/Qt/4.3/src/winmain’
    mingw32-make: *** [sub-winmain-make_default-ordered] Error 2

    C:/Qt/4.3>

  6. May 2nd, 2008,  4:04 pm

    Hi Anna;

    I can only think of two reasons mingw could start running; 1) you have not activated the visual studio paths by running vsvars32.bat. 2) you have previously used mingw and put up the variable QMAKESPEC = win32-g++ from eariler usage of Qt.

    If I kept having the same problem over and over again I would check that the QMAKESPEC were removed. I think easiest way would be to run echo %QMAKESPEC from the command prompt. If its in your registry it should prompt a value; if it does you should find the environments variables and remove this line. If you still start running mingw I would try remove the mingw path and be sure only microsoft visual studio variables were activated with vsvars32.bat.

    I hoped this helped a bit. I am not around this site every day; so please emailkentkristensen@ankanet.org if there are any further questions. I also put up a small forum at my site for any questions; but I will try change it out with some kind of commentings system like here when I get around to it.

    kindly regards,

    Kent

  7. By Thierry
    May 7th, 2008,  11:09 am

    Hello,

    did follow all procedure, but designer fails to launch. The other applications are running fine… Did someone experience that?

  8. By  Andy
    June 21st, 2008,  4:30 pm

    I have managed to get the open source edition of Qt (4.4.0) to compile with Visual Studio .NET 2005 full edition without any problems.

  9. By  .v0id
    June 22nd, 2008,  5:35 pm

    I would love to know how you did that… If you have any link you would like to share with us, go ahead…

  10. By Marco
    September 11th, 2008,  11:55 pm

    Just for reference: the QT versions without the GPL virus (i.e. commercial) do a version check on the installed IDE. Thus you can not use the QT VC 2005 precompiled installer with VC 2005 Express. A quick workaround is to fall back to the QT VC6 installer which does not do a version check. Of course it won’t be fully integrated in the IDE but it works well enough.

  11. By Harold
    September 15th, 2008,  3:17 am

    Stefan - try “configure –help”. At minimum, use configure -platform msvc-vs2008. See the included readme files for supported platforms. Also, remember to install SDKs as needed. Good luck.

  12. By  Allan
    October 29th, 2008,  7:21 am

    Thanks for these instruction, the only thing i needed to add was add %QTDIR%/lib to my path variable. Thanks so much!

  13. By DamascuS
    December 19th, 2008,  9:47 am

    Ok, ive followed all the advice here, but Qt just won’t compile for me. Im trying to compile Qt 4.3 (because 4.4 wouldn’t work either) with visual studio 2008.

    This is the last part of the output, where it moans about variables in the qdatetime.cpp file.

    cl -c -Foqdatetime.obj -W3 -nologo -O2 -I. -Igenerators -Igenerators/u
    nix -Igenerators/win32 -Igenerators/mac -IC:/Qt4.3/src/corelib/arch/generic -I
    C:/Qt4.3/include -IC:/Qt4.3/include/QtCore -IC:/Qt4.3/include -IC:/Qt4.3/includ
    e/QtCore -IC:/Qt4.3/src/corelib/global -IC:/Qt4.3/include/QtScript -IC:/Qt4.3
    /mkspecs/win32-msvc -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONEN
    T -DQT_NODLL -DQT_NO_STL -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP -DQT_BUI
    LD_QMAKE -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM
    -DQT_NO_PCRE -DQMAKE_OPENSOURCE_EDITION C:/Qt4.3/src/corelib/tools/qdatetime.
    cpp
    qdatetime.cpp
    C:/Qt4.3/src/corelib/tools/qdatetime.cpp(2175) : error C2664: ‘GetLocaleInfoA’ :
    cannot convert parameter 3 from ‘TCHAR [255]‘ to ‘LPSTR’
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-
    style cast or function-style cast
    NMAKE : fatal error U1077: ‘”C:/Program Files/Microsoft Visual Studio 9.0/VC/BIN
    /cl.EXE”‘ : return code ‘0×2′
    Stop.
    Building qmake failed, return code 2

    Now ive tried adding the reinterpret_cast operator, ive even changed the type of that variable to LPSTR, but i still get the same errors, just further down the line in another file.

    Any advice?

  14. By Guesser
    March 5th, 2009,  8:04 pm

    Does this procedure work with the newly released Qt 4.5 + Microsoft Visual Studio 2008 (Professional)?

    (I came upon this page searching for this information.. and I surely won’t be the last.. so I figured it’s worth asking)

  15. By  .v0id
    March 18th, 2009,  1:26 pm

    Sorry for replying too too late, but as u can see from the last post (1 and something years ago :D) I don’t write that much (not a dedicated blogger).

    Anyway, straight to the answer.
    You can do those steps to install Qt, but you CANNOT use it for visual studio 2008 PRO, or other edition than express. If you want to use Qt with a non-free edition of VS, you have to buy the commercial version.

    Hope I helped…

  16. By mjf
    March 19th, 2009,  4:32 am

    I just downloaded QT. and followed the steps you have.
    WHen I try to comple a file in Visual C++ 2008 express I get compiler error

    1>—— Build started: Project: testqt, Configuration: Debug Win32 ——
    1>Compiling…
    1>C4Qt.cpp

    1>`C:Program FilesMicrosoft Visual Studio 9.0VCinc1xx.dll -zm0×20000000 -il C:DOCUME~1OwnerLOCALS~1Temp_CL_9f7ce289 -typedil -f .C4Qt.cpp -Ze -D_MSC_EXTENSIONS -Zp8 -ZB64 -D_INTEGRAL_MAX_BITS=64 -Gs -pc :/ -D_MSC_VER=1500 -D_MSC_FULL_VER=150030729 -D_MSC_BUILD=1 -D_WIN32 -D_M_IX86=600 -D_M_IX86_FP=0 -GS -GR -D_CPPRTTI -Zc:forScope -Zc:wchar_t -Ot -DWIN32 -D_DEBUG -D_UNICODE -DUNICODE -FD -EHa -D_DEBUG -D_MT -D_DLL -FoDebugC4Qt.obj -FdDebugvc90.pdb -
    W 3 -Zi -EHa -D_CPPUNWIND -Gil -D_MANAGED -D_M_CEE=001 -Bd -nologo -errorreport:prompt -clrver2.00.50727.3053 -D__CLR_VER=20050727 -I C:Program FilesMicrosoft Visual Studio 9.0VCinclude -I C:Program FilesMicrosoft Visual Studio 9.0VCatlmfcinclude -I C:Program FilesMicrosoft SDKsWindowsv6.0Ainclude -I C:Program FilesMicrosoft SDKsWindowsv6.0Ainclude -I C:qt4.5.0qt-win-opensource-src-4.5.0include’

    1>.C4Qt.cpp(1) : fatal error C1083: Cannot open include file: ‘QtGui’: Permission denied
    1>Build log was saved at /file://c:Documents and SettingsOwnerMy DocumentsVisual Studio 2008ProjectsExampleslab9qtDebugBuildLog.htm/
    1>lab9qt - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    The directory path does exist.
    Any ideas?

  17. By mjf
    March 19th, 2009,  6:53 am

    I was able to compile my application without the file permission error. I just had to change to .
    Now I am getting link errors. Lots of unresolved external symbols/tokens. I did include the library path as you said. Not sure what is going wrong here. And there are qt libraries in the directory. Any ideas?

  18. By  .v0id
    March 19th, 2009,  1:12 pm

    Have you read any tutorials / articles on Qt?… If not, i suggest you do.

    I haven’t touched Qt quite some time now, but a link error is possible when you haven’t included necessary libs. Have you included qtmain.lib, QtGui4.lib, QtCore4.lib or any other libs you need?

    If not, go to your project properties->linker and add to additional dependencies the lib files you need…

    Hope it helps.

  19. March 31st, 2009,  8:13 am
  20. By Sterpu Mihai
    April 13th, 2009,  8:47 am

    In visual studio you must specify exactly where the include files are located and what libraries should be used… take this for example

    #include
    #include

    #pragma comment(lib,”QtGui4.lib”)
    #pragma comment(lib,”QtCore4.lib”)

    int main(int argc, char *argv[])
    {
    QApplication app(argc,argv);
    QPushButton button(”Hello”);
    button.resize(100,30);
    QObject::connect(&button,SIGNAL(clicked()),&app,SLOT(quit()));
    button.show();
    return app.exec();
    }

  21. By Sterpu Mihai
    April 13th, 2009,  8:48 am

    include QtGui/QApplication
    include QtGui/QPushButton

  22. April 17th, 2009,  3:25 pm

    Thank you for simplified steps for getting started with Qt and Visual Studio..

  23. By  Juraj
    April 30th, 2009,  10:55 am

    Excellent tutorial. Thanks so much, you saved me a lot of time. I combined your tutorial with this one - http://dcsoft.com/community_server/blogs/dcsoft/archive/2009/03/06/how-to-setup-qt-4-5-visual-studio-integration.aspx and didn’t have any problem with installation. I used Qt 4.5 (qt-sdk-win-opensource-2009.02.exe), Visual Studio plugin (qt-vs-addin-1.0.0.exe). OS is WIN Vista.

    I am using Microsoft Visual Studio 2008 Team System, so i don’t understand this sentence in discussion - “You can do those steps to install Qt, but you CANNOT use it for visual studio 2008 PRO, or other edition than express”. It worked for me with Team System, which is more than PRO. Maybe the problem is that with qt 4.5 you can choose between GPL and LGPL license. I chose LGPL.

    Thanks & take care. Juraj

  24. By  .v0id
    May 1st, 2009,  4:19 pm

    Firstly, thanks for your good comments on my tutorial, and I am glad it helped you.

    Secondly, thanks for the link. Haven’t read it yet, but it looks promising…

    And finally, I really had no idea it can work with Team version. I wrote this about a year ago, and I had tried it first on the VS Pro version, with no success. Thank for the update.

    Take care.

  25. May 5th, 2009,  2:26 pm

    [...] Compiling Qt 4.5.X for Visual Studio 2008 Link to where i got the original information:http://www.pc-maniac.com/?p=59 [...]

  26. By Stefano
    May 8th, 2009,  11:08 am

    Instructions for include Qt 4.5.0 and Visual C++ 2008 Express Edition:

    http://sites.google.com/site/seatibizasporttdi130/Home/software

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值