作业1
#ifndef PTR_H
#define PTR_H
template <typename T>
class Myptr
{
public:
explicit Myptr(T* p=nullptr) noexcept{} // 不可用于转换函数。
T& operator*() const; // 重载*操作符。
T* operator->() const noexcept; // 重载->操作符。
Myptr(Myptr &&other) noexcept; // 右值引用。
Myptr& operator=(Myptr &&other) noexcept; // 右值引用
Myptr(const Myptr &) = delete; // 禁用拷贝构造函数
Myptr& operator=(const Myptr &) = delete; // 禁用赋值函数
~Myptr() noexcept;
private:
T* ptr; // 内置的指针。
};
#endif // PTR_H
template<typename T>
T &Myptr<T>::operator*() const
{
return *ptr;
}
template<typename T>
T *Myptr<T>::operator->() const noexcept
{
return ptr;
}
template<typename T>
Myptr<T> &Myptr<T>::operator=(Myptr<T> &&other) noexcept
{
if(this!=&other)
{
delete ptr;
ptr = other.ptr;
other.ptr = nullptr;
}
return *this;
}
template<typename T>
Myptr<T>::~Myptr() noexcept
{
delete ptr;
}
template<typename T>
Myptr<T>::Myptr(Myptr<T> &&other) noexcept:ptr(other.ptr)
{
other.ptr = nullptr;
}
作业2
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->resize(430,330);
this->move(this->x()+750,this->y()+350);
this->setWindowIcon(QIcon("D:\\MyDoc\\QT\\homework\\icon\\1.png"));
this->setFixedSize(430,330);
this->setWindowTitle("QQ");
this->lb1 = new QLabel(this);
this->lb2 = new QLabel(this);
this->lb3 = new QLabel(this);
lb1->resize(430,130);
lb1->setScaledContents(true);
lb1->setPixmap(QPixmap("D:\\MyDoc\\QT\\homework\\icon\\2.png"));
this->le1 = new QLineEdit(this);
this->le2 = new QLineEdit(this);
le1->move(100,150); //移动位置
le1->resize(250,30);
le2->move(100,le1->y()+le1->height()+10);
lb2->resize(25,30);
lb3->resize(25,30);
lb2->setScaledContents(true);
lb3->setScaledContents(true);
lb2->move(70,150);
lb3->move(70,190);
lb3->setPixmap(QPixmap("D:\\MyDoc\\QT\\homework\\icon\\3.jpg"));
lb2->setPixmap(QPixmap("D:\\MyDoc\\QT\\homework\\icon\\1.png"));
le2->resize(250,30);
le2->setEchoMode(QLineEdit::Password);
this->cb1 =new QCheckBox(this);
this->cb2 =new QCheckBox(this);
cb1->setText("自动登录");
cb2->setText("记住密码");
cb1->move(77,230);
cb2->move(150,230);
this->btn1 = new QPushButton("注册账号",this);
this->btn2 = new QPushButton("登录",this);
this->btn3 = new QPushButton("找回密码",this);
btn3->move(250,230);
btn1->resize(70,30);
btn2->resize(270,30);
btn2->move(77,270);
btn2->setStyleSheet("background-color:skyblue; border-radius:3;");
btn3->setStyleSheet("QPushButton { background-color: rgba(255, 255, 255,0); }");
btn1->move(7,300);
btn1->setStyleSheet("QPushButton { background-color: rgba(255, 255, 255,0); }");
this-> lb4= new QLabel(this);
lb4->setPixmap(QPixmap("D:\\MyDoc\\QT\\homework\\icon\\3.png"));
lb4->move(390,295);
lb4->setStyleSheet("QPushButton { background-color: rgba(255, 255, 255,0); }");
this->widget = new QWidget(this);
widget->resize(430,330);
widget->hide();
widget->setStyleSheet("background-color:skyblue;");
this->lb5 = new QLabel(widget);
lb5->setText("登录成功");
lb5->move(200,170);
connect(this->btn2, &QPushButton::clicked, [&]()
{
if(le1->text()==le2->text())
{
widget->show();
}
});
}
MainWindow::~MainWindow()
{
}
头文件
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLabel>
#include <QIcon>
#include <QPixmap>
#include<QLineEdit>
#include<QCheckBox>
#include <QPushButton>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
QLabel *lb1;
QLabel *lb2;
QLabel *lb3;
QLabel *lb4;
QLabel *lb5;
QLineEdit *le1;
QLineEdit *le2;
QCheckBox *cb1;
QCheckBox *cb2;
QPushButton *btn1;
QPushButton *btn2;
QPushButton *btn3;
QWidget *widget;
};
#endif // MAINWINDOW_H