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

9月6日(∠・ω<)⌒☆

1、手写unique_ptr指针指针

#include <iostream>
#include <stdexcept>template <typename T>
class unique_ptr 
{
public:// 构造函数explicit unique_ptr(T* ptr = nullptr) : m_ptr(ptr) {}// 析构函数~unique_ptr() {delete m_ptr;}// 禁止复制构造函数unique_ptr(const unique_ptr&) = delete;// 禁止复制赋值运算符unique_ptr& operator=(const unique_ptr&) = delete;// 移动构造函数unique_ptr(unique_ptr&& other) noexcept : m_ptr(other.m_ptr) {other.m_ptr = nullptr;}// 移动赋值运算符unique_ptr& operator=(unique_ptr&& other) noexcept {if (this != &other) {delete m_ptr;m_ptr = other.m_ptr;other.m_ptr = nullptr;}return *this;}// 重载*和->运算符T& operator*() const {return *m_ptr;}T* operator->() const {return m_ptr;}// 获取原始指针T* get() const {return m_ptr;}// 释放所有权T* release() {T* temp = m_ptr;m_ptr = nullptr;return temp;}// 重置智能指针void reset(T* ptr = nullptr) {T* old_ptr = m_ptr;m_ptr = ptr;delete old_ptr;}private:T* m_ptr;
};int main() 
{unique_ptr<int> ptr1(new int(10));std::cout << *ptr1 << std::endl;unique_ptr<int> ptr2 = std::move(ptr1);std::cout << *ptr2 << std::endl; // 输出 10std::cout << *ptr1 << std::endl; // 不会输出什么东西return 0;
}

2、手写登录界面

头文件

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include<QPushButton>
#include<QLabel>
#include<QLineEdit>
#include<QDebug>QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();public slots:void my_slot();private:Ui::Widget *ui;QLineEdit *usernameEdit;       //账号QLineEdit *passwordEdit;       //密码QPushButton *loginButton;        //自定义登录按钮QPushButton *quitButton;          //自定义退出按钮};
#endif // WIDGET_H

源文件

#include "widget.h"
#include "ui_widget.h"#include<QLineEdit>Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);QLabel *lab1 = new QLabel("账号:",this);lab1->move(200,200);QLabel *lab2 = new QLabel("密码:",this);lab2->move(lab1->x(),lab1->y()+40);loginButton = new QPushButton("登录",this);loginButton->resize(80,40);loginButton->move(lab1->x()+120,lab1->y()+100);quitButton = new QPushButton("取消",this);quitButton->resize(80,40);quitButton->move(loginButton->x()+100,loginButton->y());usernameEdit = new QLineEdit;usernameEdit->setParent(this);usernameEdit->resize(300,30);usernameEdit->move(lab1->x()+lab1->width()+2,lab1->y()-10);passwordEdit = new QLineEdit("密码",this);passwordEdit->resize(300,30);passwordEdit->move(lab2->x()+lab1->width()+2,lab2->y()-10);passwordEdit->clear();passwordEdit->setPlaceholderText("请输入密码");passwordEdit->setEchoMode(QLineEdit::Password);connect(loginButton, &QPushButton::clicked, this, &Widget::my_slot);}Widget::~Widget()
{delete ui;
}void Widget::my_slot()
{// 获取行编辑器中的内容QString account = usernameEdit->text();QString password = passwordEdit->text();// 判断账号和密码是否正确if (account == "123456" && password == "123456"){// 登录成功qDebug() << "登录成功";this->close();}else{// 登录失败passwordEdit->setPlaceholderText("登录失败,请重新输入");passwordEdit->clear();}
}

http://www.lryc.cn/news/431725.html

相关文章:

  • k8s执行crictl images报错
  • 基于人工智能的音乐情感分类系统
  • MySQL灾难恢复策略:构建稳健的备份与恢复机制
  • docker安装DVWA(巨简单)
  • 使用matplotlab绘制多条形图
  • 五、Selenium操作指南(二)
  • Peewee+Postgresql+PooledPostgresqlDatabase重连机制
  • IIS 反向代理模块: URL Rewrite 和 Application Request Routing (ARR)
  • 企业在选择CRM系统时需要注意哪些问题呼叫系统外呼系统部署搭建
  • 数据库水平分表方案
  • MySQL表操作及约束
  • Redis 键值对操作全攻略
  • 【C语言】---- return的作用
  • 如何制作新生资料收集系统?
  • pyecharts可视化数据大屏
  • uniapp - H5 在 UC 浏览器中返回上一页失效的解决方案
  • 利用KMeans重新计算自己数据集的anchor
  • 分类任务实现模型集成代码模版
  • 从Milvus迁移DashVector
  • 彻底改变计算机视觉的 Vision Transformer (ViT) 综合指南(视觉转换器终极指南)
  • vue3 v-bind=“$attrs“ 的一些理解,透传 Attributes相关说明及事例说明
  • 鸿蒙开发基础知识-页面布局【第四篇】
  • 用CSS实现前端响应式布局
  • 【docker】docker启动sqlserver
  • Python爬虫01
  • 关于vue项目启动报错Error: error:0308010C:digital envelope routines::unsupported
  • 随笔1:数学建模与数值计算
  • SDN架构详解
  • platform框架
  • 零成本搞定静态博客——十分钟安装hugo与主题