QT Quick Dive (or QT engineering documentation)

Source: Internet
Author: User
Tags documentation qt designer

qt Quick Dive (or QT engineering documentation)

Learn and use QT for a while, and do some simple reviews.

QT is an open-source GUI software framework for Nokia, which is itself based on C + +. The efficiency is very high, not only for mobile application development, but also to open desktop applications. Integration of many GUI classes such as Qmainwindow,qwidget, Qdialog, etc., but also redefined a number of STL classes, such as Qlist,qvector, Qhash, Qmap and so on. Very convenient to use, directly under the QT framework is not allowed to other external libraries. Let's get started.
First installs the QT integrated development environment, may directly the officer online download. Internal integration of IDE:QT creator and Qt library files as well as help documentation.
Create a new project test and select QT Gui application.

The new project generally contains Test.pro,mainwindow.h, Mainwindow.cpp, Mainwindow.ui, main.cpp. Explain the contents below.
Part I.:test.pro file

QT + + Core GUI

TARGET = Test
TEMPLATE = App

SOURCES + = Main.cpp\
Mainwindow.cpp

HEADERS + = Mainwindow.h

FORMS + = Mainwindow.ui


which

The QT + + core GUI indicates that the core and GUI modules using QT are used. QT divides its library function into several modules, the most commonly used is Qtcore, Qtgui. Additional modules can be added if other modules are used. Commonly used are Qtnetwork,qtopengl, Qtsql, Qtxml. Qtwebkit and so on, if the application uses the module, the appropriate module needs to be added.
Target is, of course, the name of the generated application or link library.
Template is the type of engineering, generally have apps and Lib,app is a direct application, LIB is a dynamic link library, generally used for plug-in development.
Sources is the list of *.cpp files, when multiple lines are displayed, use \
Headers is a list of *.h files
Forms is a list of UI files, and the UI file is a QT-specific interface design file (described later).
If you do not want to use the IDE to generate the project directly, you can write a *.pro.

Part II:mainwindow.h file
#ifndef Mainwindow_h
#define Mainwindow_h

#include <QMainWindow>

Namespace Ui {
Class MainWindow;
}

Class Mainwindow:public Qmainwindow
{
Q_object

Public
Explicit MainWindow (Qwidget *parent = 0);
~mainwindow ();

Private
Ui::mainwindow *ui;
};


#endif//Mainwindow_h


The file is a declaration file for the class. The idea of interface-oriented programming in line with mainstream OOP. Typically, the definition of a class is in this file. Operations are typically no longer defined in this file. Note that the internal files inherited from Qt, must be added to the class Q_object macro definition, QT will use the MOC to re-compile the file into the Moc_mainwindow.cpp file, this is the original C + + class files. So QT built-in class files are not the original C + + class, the QT compiler needs to be processed, so the inheriting sub-QT class must add the macro definition, otherwise the compilation must not pass.
The ui::mainwindow* UI variable declaration is a Mainwindow.ui generated layout class Ui::mainwindow.

Part III:mainwindow.cpp:
#include "Mainwindow.h"
#include "Ui_mainwindow.h"

Mainwindow::mainwindow (Qwidget *parent):
Qmainwindow (parent),
UI (New Ui::mainwindow)
{
UI->SETUPUI (this);
}

Mainwindow::~mainwindow ()
{
Delete UI;
}
Is the definition file for the class. Note the # include "Ui_mainwindow.h". The Mainwindow.ui file in the project will be compiled by UIC to generate the class in the Ui_mainwindow.h file is Ui::mainwindow. The UI in MainWindow is initialized with the layout class. The UI->SETUPUI (this) is then used in the constructor, and the layout in the Ui::mainwindow can be applied to the local MainWindow.

Part IV:Mainwindow.ui is the layout file.
<?xml version= "1.0" encoding= "UTF-8"?>
<ui version= "4.0" >
<class>MainWindow</class>
<widget class= "Qmainwindow" name= "MainWindow" >
<property name= "Geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
</rect>
</property>
<property name= "WindowTitle" >
<string>MainWindow</string>
</property>
<widget class= "Qwidget" name= "Centralwidget"/>
<widget class= "Qmenubar" name= "MenuBar" >
<property name= "Geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
</rect>
</property>
</widget>
<widget class= "Qtoolbar" name= "Maintoolbar" >
<attribute name= "Toolbararea" >
<enum>TopToolBarArea</enum>
</attribute>
<attribute name= "Toolbarbreak" >
<bool>false</bool>
</attribute>
</widget>
<widget class= "Qstatusbar" name= "StatusBar"/>
</widget>
<layoutdefault spacing= "6" margin= "one"/>
<resources/>
<connections/>
</ui>
found that the content is an XML-formatted markup file, which is consistent with the mainstream UI design, now the mainstream UI design, such as Andriod and WP are using XML files to do UI design, you can use the QT SDK comes with the QT Designer for visual design, design good *. The UI file can be used directly in the project file. In the main. Pro, add the corresponding file name to forms in the *.cpp file, include the filename "Ui_*.h". After initialization, the layout can be built into its own class.

Reprint Address: http://blog.sina.com.cn/s/blog_ac823e7e010140od.html

In the original blog based on a simple revision.




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.