1) CREATE A NEW PROJECT: |
From the menu in Visual Studio, select New Project -> Visual C++ Projects -> Win32 Project -> specify project name -> Click OK Screenshot1.gif Then, Click Application Settings (on the left) -> Console Application -> Finish Screenshot2.gif |
2) MAKE SOME MINOR CODE CHANGES: |
Rename _tmain to main and
_TCHAR to char in your main.cpp class.
This step is for cross-platform compatibility. Screenshot3.gif |
Optionally, you may get rid of stdafx . stdafx.cpp in
Source and stdafx.h in Header files and click Remove
#include "stdafx.h" line from the top of
main.cpp |
3) DISABLE PRECOMPILED HEADERS: |
From the Solution Explorer, right click on the
Project_Name and select Set Create/Use Precompiled Header to Not Using Precompiled Headers Screenshot4.gif Screenshot5.gif |
4) ADD THE QT PATH FOR INCLUDES DIRECTORIES: |
From the Solution Explorer, right Click on the
Project_Name and select $(QTDIR)\lib;$(QTDIR)\include;$(QTDIR)\mkspecs\win32-msvc; Screenshot4.gif Screenshot6.gif |
5) ADD MORE QT DEPENDENCIES FOR LINKING: |
From the Solution Explorer, right Click on the
Project_Name and select Set Additional Dependencies to $(QTDIR)\lib\qt-mtedu303.lib $(QTDIR)\lib\qtmain.lib glu32.lib delayimp.lib imm32.lib winmm.lib Screenshot4.gif Screenshot7.gif |
6) GENERATE MOC FILES FOR HEADERS USING QT EVENTS (Q_OBJECT): | |
Perform this step for all header files that inherit from a
QT class - i.e. any class with Q_OBJECT .
The following example uses a ficticious header file called
MyHeaderFile.h You must fully qualify where the header file is or the moc utility will not find it. In the Solution Explorer, right Click on MyHeaderFile.h and select | |
Set Command Line to | $(QTDIR)\bin\moc MyHeaderFile.h -o tmp\moc\moc_MyHeaderFile.cpp |
Set Description to | Moc'ing MyHeaderFile.h ... |
Set Outputs to | tmp\moc\moc_MyHeaderFile.cpp |
Set Additional Dependences | $(QTDIR)\bin\moc.exe; |
Replace MyHeaderFile with the actual name of the
header file to be Moc'd.
Screenshot8.gif Screenshot9.gif |
7) ADD THE MOC FILES TO YOUR PROJECT: |
First, build your project by selecting Build -> Build
Solution or (F7) to generate moc files (you'll get
a bunch of linking errors - don't worry). From the Solution Explorer, right click on the Project_Name and select Name the new folder "Generated Moc Files" (or whatever you want). Again, from the Solution Explorer right click on the "Generated Moc Files" folder and select Lastly, locate the moc file from the directory specified in step 6 (i.e. tmp\moc\moc_MyHeaderFile.cpp) to add it to your project. That's it, you should be up and running. Good Luck. Screenshot10.gif Screenshot11.gif |
WHY USE VISUAL STUDIO .NET? |
Answer |
Shaun Tonstad and Aaron Galuzzi had fun writing this tutorial and welcome any comments or suggestions. Also welcomed are emails with "You're hired" in the subject line. |