手写登录页面,unique_ptr智能指针

手写登录页面

#include "widget.h"
#include "ui_widget.h"
#include<QDebug>
#include<QIcon>
#include<QPushButton> //按钮类
#include<QLineEdit> //行编辑器类
#include<QLabel> //标签类
#include<QMovie>
#include<QLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //更改当前页面的尺寸
    this->resize(450,300);
    //设置成固定尺寸
    this->setFixedSize(450,300);
    //有关组件的名称
    this->setWindowTitle("QQ");
    //设置窗体图标
    this->setWindowIcon(QIcon("E:\\24071QT\\day1\\LoginPage\\icon_ceefw9tu8ew\\qq_1"));
    //调用无参构造,构造一个按钮
    QPushButton *btn1=new QPushButton;
    //将自定义页面的页面当作按钮类的父组件
    btn1->setParent(this);
    //设置按钮文本内容
    btn1->setText("自动登录");
    //设置按钮大小
    btn1->resize(80,40);
    btn1->move(60,180);

    //设置按钮图标
    //btn1->setIcon(QIcon("E:\\24071QT\\day1\\LoginPage\\icon_vvytcnccyw\\denglu"));
    //4.构造按钮时,指定父组件并设置文本内容,并设置按钮图标
    QPushButton *btn2 =new QPushButton(QIcon("E:\\24071QT\\day1\\anquandenglu"),"安全登录",this);
    btn2->resize(280,30);

    //设置样式表
    btn2->setStyleSheet("background-color:skyblue;border-radius:10;");
    btn2->move(50,240);
    QPushButton *btn3 =new QPushButton("记住密码",this);
    btn3->resize(btn1->size());  //重置大小
    btn3->move(btn1->x()+btn1->width()+15,btn1->y());
    QPushButton *btn4 =new QPushButton("找回密码",this);
    btn4->resize(btn1->size());  //重置大小
    btn4->move(btn3->x()+btn3->width()+15,btn3->y());


    /**********行编辑器*********/
    QLineEdit *edit1 =new QLineEdit(this);
    edit1->move(50,90);
    edit1->resize(300,30);  //重新设置大小
    QLineEdit *edit2 =new QLineEdit("密码",this);
    edit2->resize(300,30); //重新设置大小
    edit2->move(edit1->x(),edit1->y()+edit1->height()+10);//移动位置
    edit2->clear(); //清空内容
    edit2->setPlaceholderText("密码");  //设置占位文本
    edit2->setEchoMode(QLineEdit::Password);//设置回显模式
    /**********标签类*******/
    //调用有参构造,指定父组件,构造一个lab
    QLabel *lab7=new QLabel(this);
    lab7->resize(500,80);
    QMovie *movie =new QMovie("E:\\24071QT\\day1\\01\\pictrue\\zz.gif");
    //将动图对象放入到标签中
    lab7->setMovie(movie);
    movie->start();
    //让标签内容自适应大小
    lab7->setScaledContents(true);
    //给标签弄成静态图
    QLabel *lab1 = new QLabel;
      lab1->setParent(this);          //设置父组件
      lab1->setText("账号:");          //设置文本内容
      lab1->move(btn1->x()-40, btn1->y()-90);    //设置坐标


      //2、使用有参构造完成构造一个标签
      QLabel *lab2 = new QLabel("密码:", this);
      lab2->move(lab1->x()+1, lab1->y()+40);

    lab1->resize(25,25);
       lab1->setPixmap(QPixmap("E:\\24071QT\\day1\\LoginPage\\icon_ceefw9tu8ew\\qq"));
       lab1->setScaledContents(true);
       lab2->resize(25,25);
       lab2->setPixmap(QPixmap("E:\\24071QT\\day1\\LoginPage\\icon_ceefw9tu8ew\\suoding"));
       lab2->setScaledContents(true);

       connect(btn2,&QPushButton::clicked,[=]()
       {
           if(edit1->text()==edit2->text())
           {
               qDebug()<<"登录成功";
           }
           else
           {
               qDebug()<<"登录失败";
           }
       });
}

Widget::~Widget()
{
    delete ui;
}

unique_ptr智能指针

#include <iostream>

using namespace std;
template <typename T>
class myunique_ptr
{
public:
    explicit myunique_ptr(T*p)noexcept //不可用于转换函数
    {
        ptr=p;
    }
    ~myunique_ptr() noexcept
    {
        delete ptr;
    }
    T&operator*()const  //重载*操作符
    {
        return *ptr;
    }
    T*operator->()const noexcept //重载->操作符
    {
        return  ptr;
    }
    myunique_ptr(const myunique_ptr&)=delete ;//禁止拷贝构造函数
    myunique_ptr&operator=(const myunique_ptr&)=delete ;// 禁止赋值函数
    myunique_ptr(myunique_ptr && other)noexcept //   拷贝构造函数右值引用
    {
         ptr=other.ptr;
         other.ptr=nullptr;
    }
    myunique_ptr&operator=(myunique_ptr&&other)noexcept//拷贝赋值函数
    {
        if(this!=&other)  //防止自己给自己赋值
        {
            delete this->ptr;  //释放自己之前的空间
            ptr=other.ptr;
            other.ptr=nullptr;
        }
        return *this;

    }
private:
    T* ptr;   //内置指针

};
class Test
{
public:
    string name;          //名字
    Test() {cout<<name<<"::无参构造"<<endl;}            //无参构造
    Test(string n):name(n) {cout<<name<<"::有参构造"<<endl;}  //有参构造
    ~Test() {cout<<name<<"::析构函数"<<endl;}              //析构函数
};

int main()
{

    Test *p1 = new Test("张三");          //在堆区申请空间
    myunique_ptr<Test> up1(p1);            //使用原始指针实例化一个指针指针
       cout<<"name = "<<(*p1).name<<endl;        //指针找到对象使用
       cout<<"name = "<<p1->name<<endl;          //原始指针直接使用
       cout<<"name = "<<(*up1).name<<endl;       //智能指针访问
       cout<<"name = "<<up1->name<<endl;          //智能指针访问
       cout << "********程序到此结束!********" << endl;
    return 0;
}

思维导图

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值