Qt 的核心机制

cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H
#include<stdio.h>
#include<iostream>
#include<QIcon>
#include <QPushButton>
#include<QLabel>
#include<QLineEdit>
#include<QMovie>
#include<QDebug>
#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();



private:
    QPushButton *btn1;
    QPushButton *btn2;
    QLineEdit *edit1;
    QLineEdit *edit2;
    QLabel *first;
    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);
    this->setWindowIcon(QIcon("C:\\Users\\lenovo\\Desktop\\7.png"));
    this->setFixedSize(600,400);
     this->setWindowTitle("qq");
 //   this->setWindowFlag(Qt::FramelessWindowHint);
    this->move(500,400);
    QLabel *lab1 =new QLabel(this);
    lab1->resize(600,125);
    QMovie *moive=new QMovie("C:\\Users\\lenovo\\Desktop\\1.gif");
    lab1->setMovie(moive);
    moive->start();
    lab1->setScaledContents(true);
    QLabel *lab2 =new QLabel(this);
    lab2->resize(30,30);
    lab2->move(150,lab1->y()+lab1->height()+50);
    lab2->setPixmap(QPixmap("C:\\Users\\lenovo\\Desktop\\2.png"));
    lab2->setScaledContents(true);
     this->edit1=new QLineEdit(this);
     edit1->resize(300,30);
     edit1->move(lab2->x()+lab2->width(),lab2->y());
     edit1->clear();//清空内容
     edit1->setPlaceholderText("请输入QQ账号");

     QLabel *lab3 =new QLabel(this);
     lab3->resize(30,30);
     lab3->move(lab2->x(),lab2->y()+lab2->height()+10);
     lab3->setPixmap(QPixmap("C:\\Users\\lenovo\\Desktop\\6.png"));
     lab3->setScaledContents(true);

      this->edit2=new QLineEdit(this);
      edit2->resize(300,30);
      edit2->move(edit1->x(),edit1->y()+edit1->height()+10);
      edit2->clear();//清空内容
      edit2->setPlaceholderText("请输入QQ密码");
      edit2->setEchoMode(QLineEdit::Password);

      this->btn1=new QPushButton("登录",this);
      btn1->resize(330,45);
      btn1->move(lab2->x(),lab3->y()+lab3->height()+50);
    //  btn1->setStyleSheet("background-color:orange;border-radius:10;");
     // btn1->setIcon(QIcon("C:\\Users\\lenovo\\Desktop\\jo.jpg"));

      this->first =new QLabel(this);
      first->resize(300,200);
      first->move(150,100);
      first->setStyleSheet("background-color:gray");
      QLabel*two=new QLabel(first);
      two->resize(30,80);
      two->move(150,50);


      this->btn2=new QPushButton("确认",first);
      btn2->resize(150,40);
      btn2->move(80,150);
      this->first->hide();

      connect(this->btn1,&QPushButton::clicked,[&](){

          first->show();
          if(this->edit1->text()==this->edit2->text())
          {
              first->setText("          登陆成功");
          }
          else
          {
              first->setText("    账号或密码错误");
          }
      });
      connect(this->btn2,&QPushButton::clicked,[&](){
          if(this->edit1->text()==this->edit2->text())
          {
              close();
          }
          else
          {
              this->first->hide();
          }
      });

}

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


智能指针
#include <iostream>

using namespace std;
template <typename T>
class unique_ptr
{
public:

    explicit unique_ptr(T* p):ptr(p){};
    ~unique_ptr() noexcept{

        cout<<"智能析构"<<endl;
    };
    T & operator*()const noexcept
    {
        return *ptr;
    }
    T * operator->()const noexcept
    {
        return ptr;
    }
    unique_ptr(const unique_ptr &) = delete; // 禁用拷贝构造函数
    unique_ptr& operator=(const unique_ptr &) = delete; // 禁用赋值函数
    unique_ptr& operator+=(const unique_ptr &&other) noexcept // 右值引用
    {
        this->ptr=other.ptr;
        return *this;
    }
    unique_ptr& operator+=(const unique_ptr &other) noexcept // 右值引用
    {
        this->ptr=other.ptr;
        return *this;
    }

private:
       T *ptr;
};
class A
{

public:
     string name;
    A(){cout<<"无参"<<endl;}
    A(string a):name(a){cout<<"有参"<<endl;}
    ~A(){cout<<"析构"<<endl;}
};
int main()
{
    A *p1=new A("占山");
    unique_ptr<A>up(p1);
    cout<<up->name<<endl;
    return 0;
}
相关推荐
openKaka_2 分钟前
从 scheduleUpdateOnFiber 到 Root 微任务调度:React 如何把更新交给调度系统
开发语言·前端·javascript
梦梦代码精17 分钟前
《企业开源商城选型:商业闭环、二次开发与成本平衡》
java·开发语言·低代码·开源·github
前进的李工20 分钟前
智能Agent实战指南:记忆组件嵌入技巧(记忆)
开发语言·前端·javascript·python·langchain·agent
神仙别闹34 分钟前
基于QT(C++)实现线性表的建立、插入、删除、查找等基本操作
java·c++·qt
测试员周周35 分钟前
【AI测试功能5】AI功能测试的“黄金数据集“构建指南:从0到1搭建质量评估体系
运维·服务器·开发语言·人工智能·python·功能测试·集成测试
蓝眸少年CY44 分钟前
Scala - 基础教程
开发语言·后端·scala
MATLAB代码顾问1 小时前
黏菌算法(SMA)原理详解与Python实现
开发语言·python·算法
salipopl1 小时前
C/C++ 中 volatile 关键字详解:原理、作用与实际应用
开发语言·c++
AI人工智能+电脑小能手1 小时前
【大白话说Java面试题】【Java基础篇】第39题:说说反射的用途及实现原理,Java获取反射(Class)的三种方法
java·开发语言·后端·python·面试
AIminminHu1 小时前
(让 C++ 程序长出大脑:从“语音遥控器”到具身智能 Agent 的进化之路)------OpenGL渲染与几何内核那点事------(二-1-(15))
开发语言·c++·agent·具身智能