QT 4.2.2 Installation (compile again after installation, note setting up Windows Path)

Source: Internet
Author: User

(Installation article)
Prelude:

Referring to the GUI framework estimation of C + + Most people will think of MFC, VCL, because in the COM era ten years ago, these two big guys almost monopolized the development market of the application on the C + + Windows platform, but in recent years, with the introduction of the. NET Framework. Make MFC so originally very ugly, trouble of the framework began to scenery no longer, I also learned a few days of MFC, the kind of macro as a message flying programming style let me quickly give up, several times and friends of the communication, we all think C + + is not really suitable for GUI program, But I have to face a problem: what should I use when I need to write a GUI program in C + +? I have been very hesitant, obviously, I do not like to use MFC, I am also reluctant to learn an IDE for the VCL use, and I have to write in C + + GUI is often on a non-Windows platform, it is obvious that the above two framework is more incompatible with this requirement. After a survey, I finally chose the QT This library, so also intends to open a study in this blog series.


Download:

OK, now let us set up the work environment, the Linux on the QT environment settings of the article on the Internet a lot, I do not want to be tired here, interested people can Google. I'll talk about installation and setup under Windows: First of all, we all know that QT such open source products and GCC compiler close relationship, so first we must have MINGW environment, then the first step, we must first install MINGW, I recommend a ide,dev-cpp here, He is a C + + IDE based on MinGW, with its own mingw, integrated with the GCC, g++, gdb and other tools, very useful. As follows:
Http://www.bloodshed.net/devcpp.htm


Next, we need to download QT, familiar with open source products, friends know that this product usually has two kinds of installation: first, the source installation, this download, the command line (shell) to compile locally, this Linux under the installation of software is very common; second, binary installation, Usually have the GUI interface of the graphical installation think, under Windows is usually this way of installation, in fact, the kind of installation and operating system there is no inevitable connection, just a habit, since we are under Windows, then into the township disrobed, in the second way, We need to download QT runtime for MinGW package with the following address:
http://www.trolltech.com/


Installation:

After downloading, You will get a Qt-win-opensource-4.2.2-mingw.exe file, double-click to start the installer, and usually install Windows program as basically as long as the next can, only one place to pay special attention, is he will ask you mingw path, if you install is Ming W, then write X:/mingw (x is the directory where you install MinGW), and if you install dev-c++, write the directory where you installed it, as shown in:

Of course, you can also choose to install MinGW online this time, but this depends on the network condition (here is directly connected to foreign servers, usually very slow, often disconnected), it is not encouraged to use. Finally, when the wizard finishes, you'll find a qt by Trolltech v4.2.2 (opensource) menu item in your Start menu, and it's not finished yet, because QT doesn't have a debug library, and you can't run the QT program outside of the installation directory. So expand the menu item, choose QT 4.2.2 (Build debug Libraries), will automatically compile debug library, compile time is very long, need to wait patiently, not familiar with the way of source installation friends can also experience under the source of the installation of the feeling (a command to fly, as if through the time and space ,-_-b) ...


Set up:

Although QT has its own command-line environment (QT 4.2.2 Command Prompt), we may want to make the environment variable global, so we can right-click the path of the system variable, environment variable, properties--- The following three paths are appended to the value:
X:/dev-cpp/bin
X:/dev-cpp/mingw32/bin
X:/qt/4.2.2/bin
Between directories with ";" partition, and the environment is now complete.


Inspection installation:

Qt comes with a lot of dome. We can find it under x:/qt/4.2.2/examples/, for example, we can use the command line environment into the X:/QT/4.2.2/EXAMPLES/TUTORIAL/T1 directory, and then run the qmake command to compile the program dome, if the installation is not a problem, The QT version of the Hello World program is found in the Relese directory under this directory, as shown in:

(Introductory article)

According to the habit, to learn a library, generally from writing a Hello World program, in the previous article we have seen in the library installation directory such an example, but that example only a button, too simple, not even a complete form program, In order to more deeply understand the way and thought of QT programming, we need to write a relatively complex Hello program, our program should have a panel inside the two control (a non-event control, and an event control) to form our program, for an event-driven program, This experience is more complete, OK, first of all, we can expand on the basis of the previous program, QT class names are very intuitive, so that we do not need to use the manual, we can guess some of the control's class name (really do not know can open assistant query), so a program in the blink of an eye,
Coding:

The code is as follows:
#include <QApplication.h>
#include <QLabel.h>
#include <QWidget>
#include <QFont>
#include <QPushButton.h>
int main (int argc,char* argv[])
{
Qapplication app (ARGC,ARGV);
Qwidget WinForm; As a main form
Qlabel label ("

&winform); Label Displays Hello information
Qpushbutton button ("OK", &winform); Exit Form button
Winform.resize (200,150); Set size
Label.resize (200,100);
Button.setgeometry (10, 100, 150, 40);
Button.setfont (Qfont ("The song Body", ten, Qfont::bold)); Set font
Label.setalignment (Qt::aligncenter);
Setting Event Associations
Qobject::connect (&button, SIGNAL (clicked ()), &app, SLOT (Quit ()));
Winform.show ();
return App.exec ();
}
Here are just a few things to note:
1. The header file here is almost one by one corresponding to the class used, so it's easy to understand.
2. Any QT program has to start with a class object called Qapplication, which introduces the arguments from the entry function main, returning the run result of the member function exec ().
3. There are a lot of controls that can be used for panels, and a qwidget is enough for our needs.
4. Qobject::connect (&button, SIGNAL (clicked ()), &app, SLOT (Quit ())); This code determines the association of the Click event and the handler function (quit ()) of the event that the button control needs to respond to.


Compile:

OK, the encoding is complete, save as a CPP file (such as Qhello.cpp) to a temporary directory (such as e:/tmp/), and then open our command line environment, enter this temporary directory, first, to create a QT project file, enter the command qmake-project After the carriage return we get a project file called Qt.pro, then we want to build the makefile file (this file will be set up each compile option to facilitate our subsequent compilation), continue to enter the command qmake, so we see in this directory three makefile files:
Makefile.debug: Compile options for compiling debug version (that is, version with debug information, typically for testing and debugging).
Makefile.release: Compile option to compile release version (that is, version without debug information, typically for product release).
Makefile: The total aggregator of the above two files, which he uses to respond directly to the make command.
Finally in the command line input make command, compile the project, the project is generated by default debug version of the program, you can find in the debug sub-directory, if you need to change the source code, after changing, re-made on it, if not to add new files, do not need to change the makefile and engineering files. If you are sure you can publish, you can enter the make release command to generate the release version (under the Release subdirectory).


http://blog.csdn.net/henreash/article/details/3541311

QT 4.2.2 Installation (compile again after installation, note setting up Windows Path)

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.