当前位置:网站首页>First day of QT study
First day of QT study
2022-07-28 16:43:00 【tyrocjl】
( One )Qt relevant
Can be in bash Direct execution
1)assistant(Qt assistant )//Qt Help book
2)qmake(Qt Builder )
3)designer(Qt The designer )// Graphical editing tools
4)uic(Qt Interface converter )// take ui File grab and replace with c++ Code
5)moc(Qt Metaobject compiler )// take qt Syntax extensions revert to standard C++
6)rcc(Qt Resource compiler )// Compile resources such as pictures into C++ Code
7)qtcreator(Qt Creator )//Qt The inheritance development environment of (IDE)Qt Help manual use (assistant)
1) First read the first sentence , Understand the functions of this class , If you don't understand , Sure “more” link , Jump to specify the location .
2) Move on to the header file 、 Build options (QT+=widgets)、 Inheritance relationships
3)Properties( Member variables )
4)Public Functions( Public member functions )
5)Reimplemented Public Functions( Reimplemented public virtual functions )
6)Public Slots( Slot function )//Qt Grammar extension
7)Signals( The signal )//Qt Grammar extension
8)Static Public Members( Static public members )
9)Reimplemented Protected Functions( Protected virtual functions )
10)Detailed Description( Detailed instructions )
( Two ) The first program
- Create a project directory
mkdir Hello
notes : Every Qt Programs should be placed in separate directories - Enter the project directory , Write source code (cpp)
cd Hello
vi main.cpp - perform “qmake -project”, Generate platform independent project files (Hello.pro)
notes : You need to add qmake Build options
QT += widgets // Load in the future widgets Modules correspond to header files and library files - perform “qmake”, According to the previous engineering document , Generate compilation links Makefile
- perform “make”, according to Makefile Complete compilation and linking
- test run “./Hello”
notes : If the code has syntax errors , After modifying the code , Re execution "make" that will do , front 3、4 There is no need to repeat .#include <QApplication> #include <QLabel> int main(int argc,char** argv){ // establish Qt Applications QApplication app(argc,argv); // Create a label control ( Components \ parts \ artifacts ) QLabel label("Hello Qt!"); // Show labels label.show(); // Let the application enter the event loop return app.exec(); }
( 3、 ... and )Qt character string
Common codes
1)linux System default :utf-8
2)windows System default :gbk/gb2312/gb18030
3)Qt Of QSring String default :unicode(utf-16)Code conversion class (QTextCodec)
// establish GBK Coding object
QTextCodec *codec = QTextCodec::codecForName(“GBK”);
// take GBK Convert Chinese string to unicode code
QString string = codec->toUnicode(“GBK Chinese string ”);
notes : If the structure QString String object , If there is no explicit transcoding , It's using utf-8 Of " Constant string " The default is to call fromUtf8 Automatically convert it to Qt For internal use unicode code . Of course , If not utf-8 String , It will also call by default fromUtf8, It's just a mess .
( Four ) The parent window ( Container window )
The parent window can be used to manage the entire interface , When creating a control, you can specify to dock on the parent window , If no parent window is specified, it floats outside to form a separate form .
Common parent window classes
1)QWidget // Graphic control base class
2)QMainWindow // main window (QWidget Subclass )
3)QDialog // Dialog box (QWidget Subclass )QWidget Two common member functions in class
1) Resize the parent window or control
void resize(int w,int h);
2) Adjust the position of the parent window or control
void move(int x,int y);#include <QApplication> #include <QLabel> #include <QPushButton> #include <QWidget> #include <QDialog> #include <QMainWindow> #include <QFont>// typeface int main(int argc,char** argv){ QApplication app(argc,argv); // Create a parent window object //QWidget parent; //QDialog parent; QMainWindow parent; // Set the font size of the parent window QFont font; font.setPointSize(20); parent.setFont(font); // Set the size and position of the parent window parent.resize(480,320); parent.move(200,100); // establish label And dock on the parent window QLabel label(" I'm the label ",&parent); label.move(50,50); label.resize(150,50); // establish button And dock on the parent window QPushButton button(" I'm the button ",&parent); button.move(50,200); button.resize(150,50); // Dynamically create button And dock on the parent window // When the parent window is destroyed , The dynamic objects docked above will be automatically //delete, There is no need to perform... Manually detele. QPushButton* button2 = new QPushButton(" Me too ",&parent); button2->move(300,200); button2->resize(150,50); // Show parent window , The controls docked above will also be displayed together parent.show(); return app.exec(); }
边栏推荐
- Ansa secondary development - apps and ansa plug-in management
- Redis source code optimization -- binding core
- HM二次开发 - Data Names及其使用
- Ansa secondary development - Introduction to interface development tools
- Abaqus GUI界面解决中文乱码问题(插件中文乱码也适用)
- Rosen's QT journey 101 models and views in QT quick
- laravel
- LwIP development | socket | TCP | client
- el-input限制只能输入规定的数
- ANSA二次开发 - Visual Studio Code上搭建ANSA二次开发环境
猜你喜欢

有趣的 Kotlin 0x08:What am I

Headline article_ signature

Sort 1-insert sort and Hill sort

ANSA二次开发 - Visual Studio Code上搭建ANSA二次开发环境
![[pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)](/img/e8/2044cae63fe2145ce6294cb1fdfaa0.png)
[pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)

SCI scientific paper writing Growth Camp (full version)

FX3开发板 及 原理图

About the web docking pin printer, lodop uses

KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书

HyperMesh自动保存(增强版)插件使用说明
随机推荐
asp.net大文件分块上传断点续传demo
HM二次开发 - Data Names及其使用
微软100题-天天做-第11题
Record doc
Reset grafana login password to default password
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 acfhj
Leetcode daily practice - 160. Cross linked list
2021-04-02
FX3开发板 及 原理图
8051 series MCU firmware upgrade IAP
PHP计算坐标距离
Rosen's QT journey 102 listmodel
WSL+Valgrind+Clion
Microsoft question 100 - do it every day - question 16
About the web docking pin printer, lodop uses
Sort 1-insert sort and Hill sort
PHP 图片上传
ANSA二次开发 - 在PyCharm上搭建ANSA/META二次开发环境
LwIP development | socket | TCP | client
1. Simple command line connection to database