您的位置:首页 > 汽车 > 新车 > QT day2

QT day2

2024/10/22 8:32:52 来源:https://blog.csdn.net/Artorias_Ch/article/details/141968510  浏览:    关键词:QT day2

作业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_Htemplate<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_OBJECTpublic: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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com