This document describes how to compile, install, and develop a QT application in VC 2005 using several simple steps:
1. Download and install
1. download the file. You can download it directly from the official website. My name is qt-win-opensource-4.4.3-mingw.exe;
2. Set environment variables:
My computer> Properties> advanced> environment variables> set several variables in user variables (I installed QT on the d disk ):
Add D:/QT/4.4.3/bin in path (if not, create it );
Create a qmakespec value for the win32-msvc2005, which is still based on the vs version you want to generate, 6.0 using the win32-msvc, 2003 using the win32-msvc.net, 2005 is the win32-msvc2005;
Create a qtdir value of D:/QT/4.4.3
Finally, restart cmd to make the modified environment variable take effect. You can use C:/> qmake-V to view your QT version.
3. find vsvars32.bat from the installation path of VC 2005 (subject to your own installation directory), for example, run CMD in E:/program files/Microsoft Visual Studio 8/common7/tools,
C:/> E:
E:/> program files/Microsoft Visual Studio 8/common7/tools> vsvars32.bat
D:/> Cd D:/QT/4.4.3
D:/QT/4.4.3> Configure-debug-and-release-static
D:/QT/4.4.3> nmake
The Configure-debug-and-release-static parameter indicates the static link library that QT compiles into both Debug and release versions, if no parameter is specified, the dynamic link library of the debug version is compiled. However, the latest version of qt4.5 is not recommended to be compiled to static. Generally, compilation will fail, if you have installed multiple versions of Vs, you can add-platform win32-msvc2005 (for vs2005), 6.0 use win32-msvc, 2003 use win32-msvc.net, 2008 is win32-msvc2008.configure takes about ten minutes, nmake takes about 2 hours, depending on the performance of your computer (but it takes about 3 hours to compile it, but my computer runs 4, it takes about 10 Gb of space to compile the program completely. If examples and demos are moved to another directory before nmake, the space will be saved. The version 4.5 is about 2 GB. You can run the example later. Nmake alone, but nmake will report an error when compiling the files in the examples directory. In fact, this is even if it is compiled ).
4. Run the nmake confclean command to clear the temporary files during compilation to save space;
5. add the QT path to the VC compiling environment, the tool-> options-> project and solution-> VC ++ directory, and add: d in the include file column: /QT/4.4.3/include/qtgui;
D:/QT/4.4.3/include/qtcore;
D:/QT/4.4.3/include, add D:/QT/4.4.3/lib in the library file column;
Ii. Cross-Compilation
1. Start VC, create a hello Project (empty console), and change the project settings to use the multi-byte character set, because the entry function of QT application is not Unicode;
2. start QT designer, create a form, and select a dialog box (the first option). Put a label control on the new dialog box and change its title to "Hello QT! ", Save the form to the hello project directory created with VC. The file name is hello. UI;
3. Add hello. UI as the source file to the hello project. You will be asked if you want to set properties. Click "no ";
4. close the hello project and use qmake to re-compile the VC project, this will damage the original engineering settings (you need to reset the character set-use multi-byte character sets and MFC-use MFC in shared DLL ), the usage of qmake is as follows (run the CMD command to your project directory ):
D:/Hello> qmake-project-T vcapp-O hello. Pro
D:/Hello> qmake
After compilation, replace the original. vcproj file. You do not need to specify the UI file here. qmake will create a VC project for all the UI files and C ++ files in the current directory. In addition, QT 4.4 is compatible with various VC versions. The compiling and installation steps are the same for vc6, vc2003, vc2005, and vc2008.
Note: A ui_hello.h file is automatically added to the project. However, this file is generated only after Step 1 is completed.
5. in hello. on the UI, right-click and choose Properties to change the properties. (In the Properties dialog box, select Custom generation Step> General. In the command line column, enter uic.exe hello. UI-O helloui. h: input in the description column: compiling hello. ui. In the output column, enter helloui. h. Enter uic.exe; Hello. UI, click OK.) If you don't want to change the settings, click hello. right-click the UI and choose compile. The ui_hello.h file will be generated in the current project directory. If an error occurs, modify the above hello. "Hello. ui text
Location, and then re-compile;
6. put an empty hello. CPP is added to the project (if a hello is added in step 1. if the CPP file needs to be removed and re-added, it is estimated that it was broken during qmake. double-clicking it will cause an error );
7. Open hello. cpp and add the startup code in the main function. The complete code is as follows:
// Hello. cpp: defines the entry point of the console application.
# Include "ui_hello.h" // The C ++ file generated by UI file Compilation
# Include <qtgui/qapplication>
# Include <qtgui/qmainwindow>
Int main (INT argc, char * argv [])
{
Qapplication app (argc, argv); // my myqt. UI creates a mainwindow, while the online example is dialog, but the call methods are similar.
Qmainwindow * DLG = new qmainwindow (); // The QT window object automatically recycles all the Child Window objects. The DLG here will be used as the outermost window and
Qapplication is recycled. Therefore, the QT window can only allocate objects in the heap and does not need to use Delete.
Ui: mainwindow UI; // The Class C ++ generated by mainwindow for UI file compilation. For details, see helloui. h.
Ui. setupui (DLG );
DLG-> show ();
Return app.exe C ();
}
Compile the project and run the hello program. Pai_^
Blog Source: http://blog.csdn.net/normallife/article/details/4408098