1.main.cpp:
#include "mainwindow.h"
#include <QApplication> //包含一个应用程序的头文件
/*
argc:命令行变量的数量
argv[]: 命令行变量数组
*/
int main(int argc, char *argv[])
{
QApplication a(argc, argv); //a:应用程序对象,在QT中,有且仅有一个
MainWindow w; //窗口对象
w.show(); //show方法
return a.exec(); //让应用程序对象进入消息循环机制
// while (ture)
// {
// if(点击叉子)
// {
// break;
// }
// }
}
2.mainwindow.cpp:
#include "mainwindow.h"
#include "QPushButton"
/*
命名规范:
类名:首字母大写,单词和单词之间首字母大写
函数名,变量名称:首字母小写,单词和单词之间首字母大写
快捷键:
注释: ctrl + /
运行 ctrl + r
编译 ctrl + b
查找 ctrl + f
帮助文档:F1
自动对齐: ctrl + i
同名之间的.h和.cpp切换: F4
帮助文件:
1.F1
2.
*/
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("杨会林"); //设置窗口标题
//创建一个按钮
// //方法一
// QPushButton* btn = new QPushButton;
// // btn->show(); //show方法以顶层方式弹出窗口控件
// btn->setParent(this); //让btn对象 依赖在MainWindow对象上
// btn->setText("按钮");
//方法二:
QPushButton* btn2 = new QPushButton("第二个按钮",this);
//移动按钮
btn2->move(100,100); //按钮位置
btn2->resize(100,100); //按钮大小
resize(600,400); //窗口大小
setFixedSize(600,400); //设置固定的窗口大小
connect(btn2,&QPushButton::click ,this,&QWidget::close );
}
MainWindow::~MainWindow()
{
}