Results 1 to 19 of 19

Thread: The How-To Guide: Qt4 with Visual Studio 2008

  1. #1
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Post The How-To Guide: Qt4 with Visual Studio 2008

    I've been working on a senior design project that uses Qt and VS2008. I didn't like the "free" ways that were present for using Visual Studio with Qt4, so I devised a custom build rule file and a few helper programs to make development much easier. I decided that in true open-source spirit, I should share my findings with the rest of the world.

    Attached is a zip file containing a detailed How-to of how to go about setting up your environment and how to setup a Visual Studio 2008 project from start to finish that utilizes my build method. Also in the zip file is a completed project example following the how-to, the two helper programs (autoMoc and autoUic) including their source code and the Visual Studio build rule file.

    The How-To is a bit lengthy, I tried to cover everything I could think of including potential pitfalls, so grab your favorite caffeinated drink before you begin reading!

    You can either follow the guide or use the example project to see how to setup your project. I hope this is able to help a few of you out there, I've found it to be incredibly useful.

    The advantage that my build method has is that it lets Visual Studio manage the project files. The only time you need to do anything "manual" is the fist time you make a header file with the Q_OBJECT macro, you'll need to add the generated .cpp file to your project. Other than that, the autoMoc and autoUic programs together with the build rule file will run Trolltech's Uic.exe and Moc.exe on the files that need them and only when those files have changed since the last time they were Moc'd or Uic'd.

    If you have any comments, suggestions, questions, post them here!

    Happy coding ;p
    Paul

    Updated Jan 21.2008
    1) Fixed an issue where spaces in the project path or build utility
    path would fail. Thanks to "chty" for this find and fix.
    2) Added in support to handle Qt resource files. The generated file
    appears in the Generated folder.
    3) Fixed a problem that could arise if the user cleaned the solution
    and the generated files were deleted, but the build utilities believed
    all files were up to date.

    Hopefully I'll find the free time to make an article on the Qt Wiki
    site. Until then, please refer to the readme.rtf file in the archive.
    Attached Files Attached Files
    Last edited by wysota; 22nd January 2008 at 01:05. Reason: User request, replaced attachment, new content added

  2. The following 10 users say thank you to thomaspu for this useful post:

    7thachmad (27th July 2011), abrou (12th August 2008), antia (21st January 2008), chty (18th January 2008), dc880 (31st December 2007), fanat9 (2nd August 2008), Flank4 (19th March 2010), Gira-X (2nd February 2011), Sormy (14th January 2008), The Storm (8th January 2008)

  3. #2
    Join Date
    Jan 2008
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    It does not work when you have spaces in your path of your Visual Studio project directory.
    I have tried to change the rules by adding quotes, but "Generated" directory stay empty.

  4. #3
    Join Date
    Jan 2008
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    After a few tests I have found the problem. You forget the double quotes when you run commands.

    so I'have replaced part of the program by
    Qt Code:
    1. cmd.append(" \"");
    2. cmd.append( argv[3]);
    3. cmd.append("\" \"");
    4. cmd.append( argv[4]);
    5. cmd.append("\" \"");
    6. cmd.append( argv[5]);
    7. cmd.append("\"");
    To copy to clipboard, switch view to plain text mode 

    See the two new ".cpp" files in attachment. I will provide a complete solution for this small project if you agree.

    I have add quotes in the rules file.

    Thanks you for having provided the autoMoc and autoUic source. Thanks open source program
    Attached Files Attached Files
    Chty

  5. #4
    Join Date
    Jul 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    Thank your so much for the informative explanation.
    Richard
    Last edited by drumelt; 16th July 2008 at 22:00. Reason: updated contents

  6. #5

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    Hi, thanks for helpful article.
    When i run your project, program starts like win console program.
    I'm hopeless at this. Thanks

  7. #6
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    Quote Originally Posted by alternate View Post
    Hi, thanks for helpful article.
    When i run your project, program starts like win console program.
    I'm hopeless at this. Thanks
    That is because of the console subsystem specified in the linker settings. Usually this is only default in debug configurations, and I strongly recommend keeping it for debugging purposes because all of Qt's error messages get written to that unless you write your own qt error message handler.

    If you want to get rid of this, I compiled some solutions here (clicky!).
    "If you lie to the compiler, it will get its revenge." - Henry Spencer

  8. #7
    Join Date
    Aug 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    Hi,
    I'm following your guide to setup Qt 4.4.1 with visual studio 2008 but in Step 4, after the build when it tries to run I get a Windows window with this error:

    The procedure entry point ??0QApplication@@QAE@AAHPAPADH@Z could not be located in the dynamic link library QtGuid4.dll

    What should I do?

    Thanks Advanced

  9. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    You have an old version of QtGui4.dll in PATH (could've been installed by some other application). You can verify this with Dependency Walker.
    J-P Nurmi

  10. #9
    Join Date
    Aug 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    In fact I had some old Qt dlls in the windows system 32 path =)

    Thank you for the fast answer
    ----------------------------------------------------------------------------------------------------------
    edit:

    with another project the problem is remained and the message is:

    The procedure entry point ?mapRect@QTransform@@QBE?AVQRectF@@ABV@@Z could not be located in the dynamic link library QTGui.dll.

    How should I use the depends.exe? What do I have to search with it?

    Thanks Again
    Last edited by SPir4L; 4th August 2008 at 14:03.

  11. #10
    Join Date
    Aug 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    As I edited the last post, I have not rescued with another project the problem is remained and the message is:

    The procedure entry point ?mapRect@QTransform@@QBE?AVQRectF@@ABV@@Z could not be located in the dynamic link library QTGui.dll.

    How should I use the depends.exe to verify what I have to do?

    Thanks again

    NB:
    the strange think is that with some project it goes correctly and with this one no...
    Last edited by SPir4L; 4th August 2008 at 16:10.

  12. #11
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    54
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    Well, I had used this great how to to get setup, and it worked for many days. My project was going well, until suddenly the Generated file was empty. Now, it wasn't empty a few minutes ago. What I had done, was added "$(QTDIR)\include\QtXml" to the additional include dependencies in the project properties (C/C++ -> General). I cleaned and rebuilt, and then I got this linking error:

    1>------ Build started: Project: RoboExtract, Configuration: Debug Win32 ------
    1>Auto Moc'ing RoboExtract.h
    1>Linking...
    1>RoboExtract.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QDomDocument::~QDomDocument(void)" (__imp_??1QDomDocument@@QAE@XZ) referenced in function "public: static bool __cdecl RoboExtract::readFiles(class QDir,class QString)" (?readFiles@RoboExtract@@SA_NVQDir@@VQString@@@Z)
    1>RoboExtract.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall QDomDocument::setContent(class QIODevice *,class QString *,int *,int *)" (__imp_?setContent@QDomDocument@@QAE_NPAVQIODevice @@PAVQString@@PAH2@Z) referenced in function "public: static class QDomDocument __cdecl RoboExtract:penDocument(class QString,class QString)" (?openDocument@RoboExtract@@SA?AVQDomDocument@@VQS tring@@0@Z)
    1>RoboExtract.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QDomDocument::QDomDocument(class QDomDocument const &)" (__imp_??0QDomDocument@@QAE@ABV0@@Z) referenced in function "public: static class QDomDocument __cdecl RoboExtract:penDocument(class QString,class QString)" (?openDocument@RoboExtract@@SA?AVQDomDocument@@VQS tring@@0@Z)
    1>RoboExtract.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QDomDocument::QDomDocument(class QString const &)" (__imp_??0QDomDocument@@QAE@ABVQString@@@Z) referenced in function "public: static class QDomDocument __cdecl RoboExtract:penDocument(class QString,class QString)" (?openDocument@RoboExtract@@SA?AVQDomDocument@@VQS tring@@0@Z)
    1>C:\Documents and Settings\abrounstein\My Documents\Visual Studio 2008\Projects\RoboExtract\Debug\RoboExtract.exe : fatal error LNK1120: 4 unresolved externals
    1>Build log was saved at "file://c:\Documents and Settings\abrounstein\My Documents\Visual Studio 2008\Projects\RoboExtract\RoboExtract\Debug\BuildL og.htm"
    1>RoboExtract - 5 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Essentially, linking errors, but the generated folder does not have the moc_* file.... Any suggestions?
    Last edited by abrou; 14th August 2008 at 19:03.

  13. #12
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    Double check my guide. There's a spot in there where I give an example of what to do if you want to add in more Qt stuff. In your case XML. As with any additional library you normally need two things:
    1) Tell the compiler where it can find the includes. If you don't do this, you get compile time errors. (you satisifed this part).
    2) Tell the linker what libs it can link against. If you don't do this, you get link errors.

    I'd bet that you forgot step #2 ;p

    Paul

  14. #13
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    54
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    Thanks! I had just gone back and read it and fixed it (you were right in what I forgot), and now it's working! The generated folder is still empty, but it is compiling so...Thanks!

  15. #14
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    54
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    Would any errors in the linker input additional dependencies be related to the run-time error i am now getting?

    HEAP[RoboExtract.exe]: Invalid Address specified to RtlFreeHeap( 00BD0000, 00CAA4D0 )
    Windows has triggered a breakpoint in RoboExtract.exe.

    This may be due to a corruption of the heap, which indicates a bug in RoboExtract.exe or any of the DLLs it has loaded.
    I am a little boggled, because I've never seen an error like this before.

    Thanks again

  16. #15
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    You should probably start a new thread for this cause this isn't related to my how-to guide. Just from looking at the error though, I'd bet you're doing something with a pointer that you shouldn't be. Open a new thread if you get stuck, you'll be more likely to get help from other members.

    Paul

  17. #16
    Join Date
    Sep 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    Will this work with VS2008 Professional Edition?

  18. #17
    Join Date
    Sep 2008
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    hi. i want to use dll's instead of static libraries.
    how can i do it?
    Thanks

  19. #18
    Join Date
    Jul 2007
    Posts
    121
    Thanks
    38
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    Another welcomed addition to this helpfile would be to describe a method of changing or adding new help contents in VS help system when new QT version becomes available.

    It would be nice, if there are several QT versions avaialble, to access help included with QT directly from Visual Studio.

    I would be posting such "how to" if I would only know how to include a QT help into VS help. But may be some of you know how to do it?

  20. #19
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The How-To Guide: Qt4 with Visual Studio 2008

    Quote Originally Posted by thomaspu View Post
    I've been working on a senior design project that uses Qt and VS2008. I didn't like the "free" ways that were present for using Visual Studio with Qt4, so I devised a custom build rule file and a few helper programs to make development much easier. I decided that in true open-source spirit, I should share my findings with the rest of the world.
    Just wanted to say, excellent!
    Solved my issue rather well.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.