Qt Designer can be integrated into Visual Studio using the qmsdev.dsp file that is supplied with Qt.
Start up Visual Studio and click File|Open Workspace. Open %QTDIR%\tools\designer\integration\qmsdev\qmsdev.dsp. Click Build|Set Active Configuration and in the list click 'QMsDev - Win32 Release', then click OK. Now click Build|Build qmsdev.dll. You should now copy the file %QTDIR%\tools\designer\integration\qmsdev\Release\qmsdev.dll into \Program Files\Microsoft Visual Studio\Common\MSDev98\AddIns. Now click Tools|Customize. Click the Add-in Macro Files tab, then click the Browse button. Change the file type to 'Add-ins (.dll)' and navigate to \Program Files\Microsoft Visual Studio\Common\MSDev98\AddIns. Click the qmsdev.dll file, click Open, then click Close.
A new toolbar will appear in Visual Studio with the following toolbar buttons:
New Qt Project -- A small application wizard
Generate Qt Project -- Runs qmake (or the functionally equivalent tmake) with a .pro file
New Qt Dialog -- Add an empty Qt Dialog to the active project
Qt GUI Designer -- Run Qt Designer
Use Qt -- Add the Qt libraries to the active project
Add MOC -- Add the moc precompiler to the active file
Add UIC -- Add the uic precompiler to the active file
If you create a .cpp file which contains the Q_OBJECT macro you will need an additional file which is generated by the moc to be included in your project. For example, if you have 'file.cpp', then the last line would be #include "file.moc" and the additional file would be called 'file.moc'. To ensure that Visual Studio executes the moc and generates this file you must create a custom dependency. Double click the .cpp file (in your project workspace) that contains the Q_OBJECT macro. Click the Add MOC toolbar button; this will create an empty .moc file in your project workspace. Right click the newly created .moc file, then click Settings from the pop-up menu to invoke the Project Settings dialog. Click the Custom Build tab. Click the Dependencies button to pop up the User Defined Dependencies dialog. Type in $(InputDir)\$(InputPath), then press Return. Click OK to leave the Dependencies dialog, then click OK to leave the Project Settings dialog.
If you wish to delete the add-in remove it from the toolbar then delete the qmsdev.dll file from the add-ins directory.
The qmake tool provided with Qt can create Makefiles appropriate to your platform based on .pro project files. This section describes the dependencies involved in building a Qt application and gives a couple of simple example Makefiles. This section assumes that you have a good understanding of Makefiles.
Qt Designer produces .ui files which are used to generate .h and .cpp files for the compiler to compile. The .ui files are processed by uic. Classes which inherit from QObject, e.g. those which use slots and signals, require an additional .cpp file to be generated. These files are generated by the moc and are named 'moc_file.cpp' where the original .cpp file is called 'file.cpp'. If your .cpp file contains the Q_OBJECT macro an additional file 'file.moc' should be generated which must be #included in the .cpp, normally at the end. This requires an extra dependency being created.
Processing .ui files with uic is done twice:
uic myform.ui -o myform.h uic myform.ui -i myform.h -o myform.cpp |
uic formbase.ui -o formbase.h uic formbase.ui -i formbase.h -o formbase.cpp uic -subdecl Form formbase.h formbase.ui -o form.h uic -subimpl Form formbase.h formbase.ui -o form.cpp |
For implementation files that contain classes which inherit from QObject we must create moc files:
moc myform.h -o moc_myform.cpp |
We'll look at a simple Makefile to see the dependencies in practice.
myapp: moc_myform.o myform.o main.o g++ -lqt -o myapp moc_myform.o myform.o main.o main.o: main.cpp g++ -o main.o main.cpp moc_myform.o: moc_myform.cpp g++ -o moc_myform.o moc_myform.cpp moc_myform.cpp: myform.h moc myform.h -o moc_myform.cpp myform.o: myform.cpp g++ -o myform.o myform.cpp myform.cpp: myform.h myform.ui uic myform.ui -i myform.h -o myform.cpp myform.h: myform.ui uic myform.ui -o myform.h |
In Unix/Linux environments the make command may be able to do more for us, so we should be able to use a simpler Makefile like this:
myapp: moc_myform.o myform.o main.o g++ -lq -o $@ $^ %.o: %.cpp g++ -o $^ $@ moc_%.cpp: %.h moc $^ -o $@ myform.cpp: myform.h myform.ui uic myform.ui -i myform.h -o myform.cpp myform.h: myform.ui uic myform.ui -o myform.h |