Build and compile Qt in VC Environment

Source: Internet
Author: User
Tags qt designer apple event

I. Installation

 

1. Download a qtsource package that can be used in Windows environment on trolltech.com, such as qt-win-opensource-src-4.3.4.zip, and decompress it (for example, extract it to F:/Qt-4.3.4)

2. add system environment variables, add the bin path of QT (F:/Qt-4.3.4/bin) in path, add the new variable qtdir (qtdir = F:/Qt-4.3.4 ), add the new variable qmakespec = win32-msvc.

3. Run cmd to open a DOS window and enter vcvars32.bat in vc98/bin of vc6,

4. Go to the QT main directory, execute: Configure, select 'y', and wait.

5. Execute nmake again and wait for a long time.

 

Ii. Use

 

Use notepad or VC to write a QT program, such as hello. cpp.

# Include <qapplication>

# Include <qpushbutton>

Int main (INT argc, char * argv [])

{

Qapplication app (argc, argv );

Qpushbutton Hello ("Hello world! ");

Hello. Resize (400,300 );

Hello. Show ();

Return app.exe C ();

}

Put it in the hello folder of the edisk (the working directory can be selected at will), and then execute the compilation link process as follows:

E:/> Hello> qmake-Project // create a project file unrelated to the platform

E:/> Hello> qmake hello. Pro // create a platform-specific makefile based on the project file generated in the previous step.

E:/> Hello> qmake-tp vc hello. Pro // create a vs project file through hello. Pro

E:/> Hello> nmake // compile the link Program

In the xxx. after the project file of pro, you can execute qmake-tp vc xxx. pro generates vc xxx. the DSP file can be compiled and operated on QT files in VC, which facilitates program transplantation in different systems.

 

//////////////////////////////////////// //////////////////////////////////////// ////////////////////

QT is a cross-platform C ++ graphical user interface library, produced by trolltech, Norway. QT supports all UNIX systems, including Linux systems, WINNT, Win2k, and Windows 95/98 platforms.

This document describes how to compile, install, and develop a QT application in VC 2005 using several simple steps:

1. Download and install

1. renew from the official website;

2. Find vsvars32.bat from the installation path of VC 2005, for example, run CMD in E:/program files/Microsoft Visual Studio 8/common7/tools,

C:/> E:
E:/> "E:/program files/Microsoft Visual Studio 8/common7/tools"
E:/program files/Microsoft Visual Studio 8/common7/tools> vsvars32.bat
E:/program files/Microsoft Visual Studio 8/common7/tools> D:
D:/> Cd D:/QT/4.4.0
D:/QT/4.4.0> Configure-debug-and-release-static
D:/QT/4.4.0> 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. Configure takes about 10 minutes, and nmake takes about 1 hour, depending on your computer performance.

3. 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.0/include/qtgui; D:/QT/4.4.0/include/qtcore; D:/QT/4.4.0/include; add d in the library file column: /QT/4.4.0/LIB; Add the QT installation path to the path system environment variable, for example, D:/QT/4.4.0/bin;

Ii. Cross-Compilation

1. Start VC, create a hello QT project, 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 QT project directory created with VC. The file name is hello. UI;

3. set hello. UI is added to the hello QT project as the source file. on the UI, right-click "properties" and select "Custom generation steps"> "general" in the "properties" dialog box. 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;

Note: You can also directly use qmake to compile the UI file into a VC project without manually adding the UI file. However, this will damage the original project settings, after the UI file is modified or a new UI is added, you need to re-create qmake to generate the VC project. Therefore, you can manually add and set the compiling script here. The usage of qmake is as follows:
D:/Hello QT> qmake-project-T vcapp-O helloqt. Pro
D:/Hello QT> qmake
You do not need to specify the UI file. qmake creates 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.

4. Right-click "Hello. UI" and choose "compile" to generate a helloui. h file in the current project directory;

5. Open Hello QT. cpp and add the startup code in the main function. The complete code is as follows:

// Hello QT. cpp: defines the entry point of the console application.

# Include "stdafx. H"
# Include "helloui. H" // C ++ files generated by UI file Compilation
# Include <qapplication>

Int _ tmain (INT argc, _ tchar * argv [])
{
Qapplication app (argc, argv );
Qdialog * DLG = new qdialog (); // The QT window object automatically recycles all Child Window objects. The DLG here will be used as the outermost window and will be recycled by qapplication, therefore, the QT window can only allocate objects in the heap without using Delete.

Ui: Dialog UI; // The C ++ class generated by Dialog for UI file compilation. For details, see helloui. h.
Ui. setupui (DLG );

DLG-> show ();

Return app.exe C ();
}

Add qtcore. Lib qtgui. lib to add dependencies to the Project Settings, compile the project, and run the hello QT program.

The message mechanism in Windows is an apple event on Mac platform, and the drivers vary by platform. QT unifies these inconsistent platform mechanisms, A signal and slot mechanism is formed to process various system events for cross-platform purposes. Therefore, QT programs can be compiled on other platforms without any modification.

//////////////////////////////////////// /////////////////////////////

 

Qt4.3.0 Installation Guide in VC ++ 6.0

 

//////////////////////////////////////// //////////////////////////////////////// ////

I have referenced some materials to share with you the process of installing Qt in vc6.0.
1. Compile QT

1) download the source code package of QT (Note: The suffix is. zipsuffix, and the package of .exe suffix is the source code file of the compiler using mingw ).

2) decompress the QT source code to the hard disk.

Example: C:/QT/4.3.0/or C:/QT/4.3.0-msvc/

2. Download and install the patch that allows QT to be compiled with VC.

1) download acs-4.3.0-patch2.zip from the website sourceforge.net.

2) decompress it to the QT source code directory.

3. Open the command line tool and switch the path to the QT source code directory.

Run cmd.exe, switch to C:/program files/Microsoft Visual Studio/vc98/bin (VC path), run vcvars32.bat, and set the path of the compiled vc6.0 file.

Check whether nmake.exe is in the path:

D:/QT/4.3.0> nmake /?

Microsoft (r) program maintenance utility version 6.00.8168.0

Copyright (c) Microsoft Corp1988-1998. All rights reserved.

Usage: nmake @ commandfile
Nmake [Options] [/F makefile] [/X stderrfile] [macrodefs] [targets]

Options:

4 patch the QT source code

Run D:/QT/4.3.0> installpatch43.bat

The following content is displayed:

D:/QT/4.3.0> installpatch43.bat
Patching file qconfigure. bat
Patching file examples/Threads/waitconditions. Pro
Patching file MISC/bcc32pch/makefile. win32-borland
Patching file MISC/bcc32pch/bcc32pch. cpp
Patching file MISC/bcc32pch/bcc32pch. PRI
Patching file MISC/bcc32pch/bcc32pch. Pro
Patching file mkspecs/win32-bccx/qmake. conf

5. Install QT

If zookeeper is not clear, you can run configure-opensource.exe

Then run D:/QT/4.1.1> qconfigure. Bat msvc

At the beginning, I will ask whether to accept gpllicence and enter y. Then there is a long wait.
It is said that there will be an error during compilation (but I did not encounter it), fatal error c1083: cannot open include file: 'uxtheme. H': no such file or directory

Prompt uxtheme. H and tmschema. h cannot be found, while schemadef. H is in tmschema. h, so three other files are required, which are not in vc6, including platformsdk in Windows platformsdk which is switched to Visual Studio 2003 or Visual Studio 2005. If you have installed the SDK, you do not have to spend any time downloading the 385.0 mb sdk. By default, all three files are installed in
C:/program files/Microsoft Visual Studio 8/VC/platformsdk/include
(Uxtheme. h defines the uxtheme API referenced in the corresponding code example in the step of adding a style to the control, and tmschema. h defines various classes.

You can download http://www.cnblogs.com/xcvm/archive/2006/03/08/346013.html here

Add these three files to the include folder of VC and compile the files.

Another error is nmake: Fatal error u1077: 'cl.exe ': return code: '0x80' stop.

I searched the internet and said it was the cause of insufficient memory. I also encountered this problem. I restarted my computer and opened only one window for compiling QT, so there was no problem.

6. Set Environment Variables

Path = D:/QT/4.1.1/bin

Qmakespec = win32-msvc

Restart the instance.
Check whether the path settings are correct:

C:/> qmake-V
Qmake version: 2.00a
Using QT version 4.1.1 In D:/QT/4.1.1/lib

C:/> echo % qmakespec %
Win32-msvc

So far, QT has been installed.

Let's test it with a small program.

Create a file named hello. cpp and enter the following code:

# Include <qapplication>
# Include <qlabel>

Int main (INT argc, char ** argv ){
Qapplication app (argc, argv );
Qlabel * label = new qlabel ("Hello world! ");

Label-> show ();

Return app.exe C ();
}

Then

Prompt> qmake-project-O hello. Pro

Prompt> qmake

Prompt> nmake

A. EXE file is generated under the debug folder.

//////////////////////////////////////// ////////////////////////////////////

//////////////////////////////////////// //////////////////////////////////////// /////

For more information, see.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.