当前位置: 首页 > news >正文

C++学习9.28

1> 创建一个新项目,将默认提供的程序都注释上意义

por

QT       += core gui
#QT表示引入的类库   core:核心库例如IO操作在该库中    gui:图形化显示库
#如果要使用其他类库中的相关函数,就需要调用相关类库后,才能加以使用greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
#QT版本超过4时,会自动加上widgetsCONFIG += c++11
#支持C++11的新特性# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0#用来实现项目工程的管理
#管理源文件
SOURCES += \main.cpp \widget.cpp#管理头文件
HEADERS += \widget.h#管理所有的ui文件
FORMS += \widget.ui# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target头文件
#ifndef WIDGET_H
#define WIDGET_H
//防止头文件重复包含#include <QWidget>//ui_mywnd.h中的命名空间的声明
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }      //将其他文件中的命名空间进行声明
QT_END_NAMESPACE//自定义的类的声明,公共继承自QWidget
//QWidget类中封装了有关图形化界面相关的操作
class Widget : public QWidget
{Q_OBJECT    //信号与槽的元对象,没有这个就没法办使用信号与槽public:Widget(QWidget *parent = nullptr);      //构造函数的声明,使用了默认参数构造~Widget();                  //虚函数private:Ui::Widget *ui;             //成员函数,指针
};
#endif // WIDGET_H源文件
#include "widget.h"
#include "ui_widget.h"//构造函数的定义
Widget::Widget(QWidget *parent): QWidget(parent)           //在子类初始化中调用父类的有参构造,来完成子类从父类中继承的成员的初始化, ui(new Ui::Widget)        //给自己类中的指针成员实例化空间
{ui->setupUi(this);          //将ui界面上的组件展示在this界面上
}Widget::~Widget()
{delete ui;              //释放ui界面申请的组件空间
}主函数
#include "widget.h"
//自定义头文件,该文件包含了图形化界面类#include <QApplication>
//包含应用程序的头文件int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;            //使用自定义的类无参构造一个界面对象w.show();           //调用对象的函数成员,将界面输出出来return a.exec();//a.out():使用应用程序类对象,调用应用程序的成员函数,保证界面不被关闭,轮询等待界面发生变化//等待用户操作界面上的组件//等待界面上的槽与信号的相应//等待事情处理机制的实现}

2> 使用代码的形式实现登录框

#include "widget.h"
#include <QDebug>
#include <QIcon>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>Widget::Widget(QWidget *parent): QWidget(parent){//输出数据qDebug()<<"hellow";//更改窗口名字qDebug()<<"当前界面标题为:"<<this->windowType();this->setWindowTitle("My first window");//更改窗口图标this->setWindowIcon(QIcon("C:/Users/ASUS/Desktop/wenjian.png"));//设置窗口尺寸qDebug()<<"width:"<<this->width()<<"  height:"<<this->height();qDebug()<<"size :"<<this->size();this->setMaximumSize(800,600);this->setMinimumSize(QSize(400,300));this->resize(700,600);
//    this->setFixedSize((500,400));//标签组件(账号密码)QLabel *label1 = new QLabel(this);label1->setText("账号");label1->resize(40,40);label1->move(130,300);QLabel *label2 = new QLabel(this);label2->setText("密码");label2->resize(label1->size());
//    label2->move(label1->x(),label1->y()+width()+10-label2->y());label2->move(130,340);//行编辑(账号密码的输入)QLineEdit *line1 = new QLineEdit(this);line1->resize(300,30);line1->move(label1->x()+label1->width()+2,label1->y());QLineEdit *line2 = new QLineEdit(this);line2->resize(300,30);line2->move(label2->x()+label2->width()+2,label2->y());line2->clear();line2->setPlaceholderText("             请输入密码");line2->setEchoMode(QLineEdit::Password);//按钮(登录/退出)QPushButton *btn1 = new  QPushButton(this);btn1->setText("登录");btn1->resize(80,40);btn1->move(250,400);btn1->setStyleSheet("color:white;background-color:skyblue;border-radius:10px;");QPushButton *btn2 = new  QPushButton(this);btn2->setText("退出");btn2->resize(80,40);btn2->move(350,400);btn2->setStyleSheet("color:red;background-color:yellow;border-radius:10px;");//logoQLabel *lab = new QLabel(this);lab->resize(120,120);lab->setPixmap(QPixmap("C:/Users/ASUS/Desktop/新建文件夹/图/图.jpg"));lab->setScaledContents(true);lab->move(270,150);}Widget::~Widget()
{
}

3> 思维导图


http://www.mrgr.cn/news/38527.html

相关文章:

  • 不将“旧”,换新家电的门槛又被TCL拉低了
  • C++使用库(静态链接)
  • K8S真正删除pod
  • 【SQL】未订购的客户
  • 第十四届蓝桥杯真题Java c组D.平均(持续更新)
  • SpringCloud入门(九)Feign实战应用和性能优化
  • OpenCV透视变换:原理、应用与实现
  • Makefile编程:4种赋值差异
  • MySQL基础--表的增删改查
  • 算法复杂度-空间
  • 找不到msvcp110.dll怎么办,总结6种解决msvcp110.dll的方法
  • 大数据毕业设计选题推荐-食品销售数据分析系统-Hive-Hadoop-Spark
  • css 数字比汉字要靠上
  • 【刷点笔试面试题试试水】 i++与++i哪个效率更高?
  • webpack 和 vite 区别
  • Accelerate单卡,多卡config文件配置
  • 对小白友好的与易我同级别四款剪辑工具推荐:
  • Xshell连接服务器
  • Spring Boot 整合 Keycloak
  • 花都狮岭寄宿自闭症学校:开启孩子的生命之门