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所有的命名空间
|
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 |
|
|
Contains classes from the Qt3DExtras module |
|
|
... |
... |
|
Contains miscellaneous identifiers used throughout the Qt library 包含很多枚举类型定义,比如一些颜色值,Qt::white、Qt::black |
|
|
... |
... |
All Modules Qt模块
Qt Essentials 基本模块
The following table lists the Qt essentials:
| Module | Description |
|---|---|
| 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:
| Module | Development Platforms | Target Platforms | Description |
|---|---|---|---|
| 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
|
... |
... |
|
Provides core non-GUI functionality |
|
|
Qt GUI module provides the basic enablers for graphical applications written with Qt |
|
|
Provides C++ classes for using gamepads |
|
|
Provides classes for integrating online documentation in applications |
|
|
Provides C++ interfaces to retrieve location and navigational information |
|
|
Provides classes and functions specific to macOS and iOS operating systems |
|
|
Qt Multimedia module provides audio, video, radio and camera functionality |
|
|
... |
... |
Qt Core C++ Classes http://doc.qt.io/qt-5/qtcore-module.html
|
Output stream for debugging information |
|
|
The base class of all event classes. Event objects contain event parameters |
|
|
The base class of all Qt objects |
|
|
Contains meta-information about Qt objects |
|
|
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>
|
Hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device |
|
|
Manages the GUI application's control flow and main settings |
|
|
Represents a window in the underlying windowing system |
|
|
Colors based on RGB, HSV or CMYK values |
|
|
Specifies a font used for drawing text |
|
| ... | ... |
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 };
类 MainWindow 继承自 QMainWindow ,最终继承自 QObject
豆子有篇文章讲的很清楚:
只有继承了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类 的指针
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 }
#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
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 与语言翻译有关
#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }

浙公网安备 33010602011771号