Qt note

Qt 5.8http://doc.qt.io/qt-5/index.html

Qt Reference Pages http://doc.qt.io/qt-5/reference-overview.html

All Namespaces 命名空间http://doc.qt.io/qt-5/namespaces.html

This is a list of the main namespaces in Qt.     Qt所有的命名空间

Qt3DCore

Contains classes that are the foundation for Qt 3D simulation framework, as well as classes that provide the ability to render using the Qt 3D framework

Qt3DExtras

Contains classes from the Qt3DExtras module

...

...

Qt

Contains miscellaneous identifiers used throughout the Qt library

包含很多枚举类型定义,比如一些颜色值,Qt::white、Qt::black

...

...

 

All Modules  Qt模块

Qt Essentials  基本模块

 

The following table lists the Qt essentials:

ModuleDescription
Qt Core Core non-graphical classes used by other modules.
Qt GUI Base classes for graphical user interface (GUI) components. Includes OpenGL.
Qt Multimedia Classes for audio, video, radio and camera functionality.
Qt Multimedia Widgets Widget-based classes for implementing multimedia functionality.
Qt Network Classes to make network programming easier and more portable.
Qt QML Classes for QML and JavaScript languages.
Qt Quick A declarative framework for building highly dynamic applications with custom user interfaces.
Qt Quick Controls Reusable Qt Quick based UI controls to create classic desktop-style user interfaces.
Qt Quick Dialogs Types for creating and interacting with system dialogs from a Qt Quick application.
Qt Quick Layouts Layouts are items that are used to arrange Qt Quick 2 based items in the user interface.
Qt SQL Classes for database integration using SQL.
Qt Test Classes for unit testing Qt applications and libraries.
Qt Widgets Classes to extend Qt GUI with C++ widgets.

If you use qmake to build your projects, the Qt Core and Qt GUI modules are included by default. To link only against Qt Core, add the following line to your .pro file:  

(用qmake构建时,Qt Core 和 Qt GUI 默认已经添加,如下.pro文件所示,当不需要图形GUI模块时可以用QT -= guiQT -= guiQT -= gui

QT -= gui

On Windows, if you do not use qmake or other build tools such as CMake, you also need to link against the qtmain library.

Qt Add-Ons 附加模块

The following table lists the Qt add-ons:

ModuleDevelopment PlatformsTarget PlatformsDescription
Active Qt Windows   Classes for applications which use ActiveX and COM
Qt 3D All   Functionality for near-realtime simulation systems with support for 2D and 3D rendering.
Enginio (Deprecated) All All A Backend-as-a-Service solution to ease the backend development for connected and data-driven applications.
Qt Android Extras All Android Provides platform-specific APIs for Android.
...      

All Classes by Module http://doc.qt.io/qt-5/modules-cpp.html

These are the C++ API pages for Qt 5's modules. For a list of all classes on a single page, visit the All Classes page.
 

...

...

QtCore

Provides core non-GUI functionality

QtGui

Qt GUI module provides the basic enablers for graphical applications written with Qt

QtGamepad

Provides C++ classes for using gamepads

QtHelp

Provides classes for integrating online documentation in applications

QtLocation

Provides C++ interfaces to retrieve location and navigational information

QtMacExtras

Provides classes and functions specific to macOS and iOS operating systems

QtMultimedia

Qt Multimedia module provides audio, video, radio and camera functionality

...

...

Qt Core C++ Classes     http://doc.qt.io/qt-5/qtcore-module.html

Provides core non-GUI functionality. 所有Qt模块都依赖这个模块,包含此模块用  #include <QtCore>
此模块包含的类有如下

QDebug

Output stream for debugging information

QEvent

The base class of all event classes. Event objects contain event parameters

QObject

The base class of all Qt objects

QMetaObject

Contains meta-information about Qt objects

QTimer

Repetitive and single-shot timers

...     ...
 

Qt GUI C++ Classes http://doc.qt.io/qt-5/qtgui-module.html

The Qt GUI module provides the basic enablers for graphical applications written with Qt.    使用 #include <QtGui>

此模块包含的类有如下
 

QImage

Hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device

QGuiApplication

Manages the GUI application's control flow and main settings

QWindow

Represents a window in the underlying windowing system

QColor

Colors based on RGB, HSV or CMYK values

QFont

Specifies a font used for drawing text

...     ...
简单 Qt Widgets Application 程序分析
 
 mainwindow.h
 1 #include <QMainWindow>
 2 namespace Ui {
 3 class MainWindow;
 4 }
 5 class MainWindow : public QMainWindow
 6 {
 7 Q_OBJECT
 8 public:
 9 explicit MainWindow(QWidget *parent = 0);
10 ~MainWindow();
11 private:
12 Ui::MainWindow *ui;
13 };
View Code

类 MainWindow 继承自 QMainWindow ,最终继承自 QObject

类 MainWindow 包含一个 宏 Q_OBJECT ,此宏在 QObject  类中定义  http://doc.qt.io/qt-5/qobject.html#Q_OBJECT
The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and slots or that uses other services provided by Qt's meta-object system. 要使用Qt 的信号与槽必须包含Q_OBJECT 宏,Q_OBJECT 宏也提供了Qt 元对象系统的其他功能。

豆子有篇文章讲的很清楚:

只有继承了QObject类的类,才具有信号槽的能力。所以,为了使用信号槽,必须继承QObject。凡是QObject类(不管是直接子类还是间接子类),都应该在第一行代码写上Q_OBJECT。不管是不是使用信号槽,都应该添加这个宏。这个宏的展开将为我们的类提供信号槽机制、国际化机制以及 Qt 提供的不基于 C++ RTTI 的反射能力。因此,如果你觉得你的类不需要使用信号槽,就不添加这个宏,就是错误的。其它很多操作都会依赖于这个宏。注意,这个宏将由 moc(我们会在后面章节中介绍 moc。这里你可以将其理解为一种预处理器,是比 C++ 预处理器更早执行的预处理器。) 做特殊处理,不仅仅是宏展开这么简单。moc 会读取标记了 Q_OBJECT 的头文件,生成以 moc_ 为前缀的文件,比如 newspaper.h 将生成 moc_newspaper.cpp。你可以到构建目录查看这个文件,看看到底增加了什么内容。注意,由于 moc 只处理头文件中的标记了Q_OBJECT的类声明,不会处理 cpp 文件中的类似声明。因此,如果我们的Newspaper和Reader类位于 main.cpp 中,是无法得到 moc 的处理的。解决方法是,我们手动调用 moc 工具处理 main.cpp,并且将 main.cpp 中的#include "newspaper.h"改为#include "moc_newspaper.h"就可以了。不过,这是相当繁琐的步骤,为了避免这样修改,我们还是将其放在头文件中。许多初学者会遇到莫名其妙的错误,一加上Q_OBJECT就出错,很大一部分是因为没有注意到这个宏应该放在头文件中。
来源: https://www.devbean.net/2012/08/qt-study-road-2-custom-signal-slot/

explicit MainWindow(QWidget *parent = 0); 这个是类MainWindow的构造函数,explicit 关键字是用来防止隐式转换的http://baike.baidu.com/item/explicit?sefr=sebtn
~MainWindow(); 析构函数
 Ui::MainWindow *ui;  定义一个指向Ui::MainWindow类 的指针

 
 
mainwindow.cpp
 1 #include "mainwindow.h"
 2 #include "ui_mainwindow.h"
 3 MainWindow::MainWindow(QWidget *parent) :
 4 QMainWindow(parent), //调用父类的构造函数
 5 ui(new Ui::MainWindow) //初始化列表
 6 {
 7 ui->setupUi(this); //调用setupUi(), 把UI中的组件树都添加到this,即当前对象MainWindow
 8 }
 9 MainWindow::~MainWindow()
10 {
11 delete ui;
12 }
View Code
一般函数都在 .h文件中定义,在 .cpp文件中实现,
#include "ui_mainwindow.h"  ui_mainwindow.h
Qt Designer 设计的界面信息位于 .ui 文件中 ,如mainwindow.ui Qt Designer UI files represent the widget tree of the form in XML format. http://doc.qt.io/qt-5/designer-using-a-ui-file.html
ui文件在编译和运行时被转换成C++ code,如ui_mainwindow.h ,这个文件就工程编译目录下
 内容主要为以下所示:
class Ui_MainWindow
{
public:
QMenuBar *menuBar;
QToolBar *mainToolBar;
QWidget *centralWidget;
QStatusBar *statusBar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QStringLiteral("MainWindow"));
MainWindow->resize(400, 300);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QStringLiteral("menuBar"));
MainWindow->setMenuBar(menuBar);
mainToolBar = new QToolBar(MainWindow);
mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
MainWindow->addToolBar(mainToolBar);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
MainWindow->setCentralWidget(centralWidget);
statusBar = new QStatusBar(MainWindow);
statusBar->setObjectName(QStringLiteral("statusBar"));
MainWindow->setStatusBar(statusBar);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", Q_NULLPTR));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
View Code

 

 
类MainWindow 继承 Ui_MainWindow
 QMenuBar *menuBar; //Ui_MainWindow 有指向界面中各组件如menuBar、statusBar等的指针
void setupUi(QMainWindow *MainWindow) // to build the widget tree on the parent widget 
 void retranslateUi(QMainWindow *MainWindow)   //handles the translation of the string properties of the form 与语言翻译有关


main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
View Code
QApplication a(argc, argv);  
Application::QApplication(int &argc, char **argv) http://doc.qt.io/qt-5/qapplication.html#QApplication
    Initializes the window system and constructs an application object with argc command line arguments in argv.(用参数agrc、agrv初始化window system 并构建一个application 对象)
      int QApplication::exec() 
       Enters the main event loop and waits until exit() is called, then returns the value that was set to exit() (进入主事件循环,等待直到exit()被调用)
      [slot] void QWidget::show()   http://doc.qt.io/qt-5/qwidget.html#show
       Shows the widget and its child widgets. (显示出widgets树)
 
 类关系继承图(MainWindow)

 


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
posted @ 2017-03-28 19:35  23hour  阅读(283)  评论(0)    收藏  举报
Edit