PDA

View Full Version : The How-To Guide: Qt4 with Visual Studio 2008



thomaspu
28th December 2007, 00:32
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.

chty
18th January 2008, 14:01
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.

chty
18th January 2008, 15:18
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


cmd.append(" \"");
cmd.append( argv[3]);
cmd.append("\" \"");
cmd.append( argv[4]);
cmd.append("\" \"");
cmd.append( argv[5]);
cmd.append("\"");


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

drumelt
16th July 2008, 21:51
Thank your so much for the informative explanation.
Richard

alternate
2nd August 2008, 15:51
Hi, thanks for helpful article.
When i run your project, program starts like win console program.
I'm hopeless at this. Thanks

Methedrine
3rd August 2008, 12:25
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!) (http://www.methedrine.org/index.php?/archives/10-Qt,-Visual-Studio-and-the-Windows-Subsystem.html).

SPir4L
4th August 2008, 10:34
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?:confused:

Thanks Advanced

jpn
4th August 2008, 10:42
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 (http://www.dependencywalker.com/).

SPir4L
4th August 2008, 11:01
:) In fact I had some old Qt dlls in the windows system 32 path =)

Thank you for the fast answer :D
----------------------------------------------------------------------------------------------------------
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

SPir4L
4th August 2008, 16:01
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...

abrou
14th August 2008, 18:58
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::openDocument(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::openDocument(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::openDocument(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?

thomaspu
14th August 2008, 19:11
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

abrou
14th August 2008, 19:12
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!

abrou
14th August 2008, 21:59
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

thomaspu
14th August 2008, 22:09
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

kingkluck
8th September 2008, 16:25
Will this work with VS2008 Professional Edition?

akasi
11th September 2008, 17:53
hi. i want to use dll's instead of static libraries.
how can i do it?
Thanks

QPlace
26th October 2008, 13:23
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?

Flank4
19th March 2010, 03:47
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. :)