Table of contents
1. Create the first Qt program
01_FirstProject.pro file explanation
Explanation of the mywidget.h header file
Naming conventions and common shortcut keys
1. Create the first Qt program
Open the Qt Creator interface and select New Project or select the menu bar [File] - [New File or Project] menu item
The New Project dialog box pops up, select Qt Widgets Application,
Select the [Choose] button, and the following dialog box will pop up
Set the project name and path, follow the wizard to the next step,
Select build suite
The wizard will add a class inherited from CMainWindow by default, and the name and base class of the class can be modified here. The default base classes are QMainWindow, QWidget and QDialog. We can choose QWidget (similar to an empty window). Here we can create an interface without UI first and continue to the next step
The system will add main.cpp, mywidget.cpp, mywidget.h and a .pro project file to us by default. Click Finish to create a Qt desktop program.
Adjust Chinese: Tool→options→envirment→language
2. Project explanation
Explanation of main.cpp
01_FirstProject.pro file explanation
Explanation of the mywidget.h header file
3. Naming conventions and common shortcut keys
Naming convention
Class name capitalizes the first letter, capitalizes the first letter between words
Function name variable name capitalizes the first letter between words and words
Shortcut keys
comment ctrl + /
run ctrl + r
compile ctrl + b
font zoom ctrl + mouse wheel
find ctrl + f
overall movement ctrl + shift + ↑ or ↓
help document F1
automatically align ctrl + i
between .h and .cpp of the same name Toggle F4
The first method of help documentation is F1 The second method is the left button The third method C:\Qt\Qt5.8.0\5.8\mingw53_32\bin
summary:
1.1 点击创建项目后,选择项目路径以及 给项目起名称
1.2 名称 - 不能有中文 不能有空格
1.3 路径 - 不能有中文路径
1.4 默认创建有窗口类,myWidget,基类有三种选择: QWidget、QMainWindow、QDialog
1.5 main函数
1.5.1 QApplication a 应用程序对象,有且仅有一个
1.5.2 myWidget w;实例化窗口对象
1.5.3 w.show()调用show函数 显示窗口
return a.exec() 让应用程序对象进入消息循环机制中,代码阻塞到当前行