页面设置
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
speecher = new QTextToSpeech(this);
this->setFixedSize(480,410);//设置窗口固定大小
this->setStyleSheet("border-radius:10px;");
this->setWindowTitle("聊天室");//设置窗口标题
this->setWindowIcon(QIcon(":/icon/wodepeizhenshi.png"));//设置窗口图标
QLabel *La1 = new QLabel(this);//构造标签组件及指定父组件
La1->resize(480,180);
La1->setPixmap(QPixmap(":/icon/logo.png"));//设置图片
QLabel *La2 = new QLabel(this);//构造标签组件及指定父组件
La2->resize(45,40);
// La2->setStyleSheet("border-radius:10px;");
La2->setPixmap(QPixmap(":/icon/userName.jpg"));
La2->setScaledContents(true);
La2->move(La1->x()+80,La1->y()+215);
QLabel *La3 = new QLabel(this);//构造标签组件及指定父组件
La3->resize(45,40);
La3->setPixmap(QPixmap(":/icon/passwd.jpg"));
La3->setScaledContents(true);
La3->move(La2->x(),La2->y()+60);
edit1 = new QLineEdit(this);
edit1->setPlaceholderText("QQ/手机/邮箱");
qDebug() << edit1->text();
edit1->resize(200,43);
edit1->move(La2->x()+81,La2->y());
edit2 = new QLineEdit(this);
edit2->setPlaceholderText("密码");
qDebug() << edit1->text();
edit2->resize(200,43);
edit2->move(La3->x()+81,La3->y());
edit2->setEchoMode(QLineEdit::Password);
btn1 = new QPushButton(QIcon(":/icon/login.png"),"登录",this);
btn1->resize(88,38);
qDebug()<<btn1->size();
// btn1->setEnabled(false);
btn1->move(edit2->x()+58,edit2->y()+65);
btn1->setStyleSheet("border-radius:10px;border:1px solid grey;");
btn2 = new QPushButton(QIcon(":/icon/cancel.png"),"取消",this);
btn2->resize(btn1->size());
// btn2->setEnabled(false);
btn2->move(btn1->x()+130,btn1->y());
btn2->setStyleSheet("border-radius:10px;border:1px solid grey;");
connect(btn1,&QPushButton::clicked,this,&Widget::my_slot);
connect(btn2,SIGNAL(pressed()),this,SLOT(Btn2_click()));
connect(this,&Widget::jump,[&](){
speecher->say("傻逼,你还真登录!");
});
}
Widget::~Widget()
{
delete ui;
}
void Widget::my_slot()
{
QString name =edit1->text();
QString passw =edit2->text();
if( name == "admin" && passw=="123456")
{
qDebug() << "登录成功";
emit jump();
this->close();
}else
{
qDebug() <<"登录失败";
edit2->clear();
}
}
void Widget::Btn2_click()
{
emit jump1();
}
void Widget::qxiao_slot()
{
this->close();
}
#include "quxiao.h"
#include "ui_quxiao.h"
Quxiao::Quxiao(QWidget *parent) :
QWidget(parent),
ui(new Ui::Quxiao)
{
ui->setupUi(this);
}
Quxiao::~Quxiao()
{
delete ui;
}
void Quxiao::on_btn1_clicked()
{
emit jump1();
this->close();
}
void Quxiao::on_btn2_clicked()
{
this->close();
}
void Quxiao::jump_slot1()
{
this->show();
}
#include "delu.h"
#include "ui_delu.h"
Delu::Delu(QWidget *parent) :
QWidget(parent),
ui(new Ui::Delu)
{
ui->setupUi(this);
}
Delu::~Delu()
{
delete ui;
}
void Delu::jump_slot()
{
this->show();
}
头文件
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QDebug> //输出函数对应的头文件
#include <QIcon>
#include <QLineEdit>
#include <QString>
#include <QTextToSpeech>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
signals:
void my_signal();
signals:
void jump();
void jump1();
public slots:
void my_slot();
public slots:
void Btn2_click();
void qxiao_slot();
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
Ui::Widget *ui;
QPushButton *btn1;
QPushButton *btn2;
QLineEdit *edit1;
QLineEdit *edit2;
QTextToSpeech *speecher;
};
#endif // WIDGET_H
#ifndef QUXIAO_H
#define QUXIAO_H
#include <QWidget>
namespace Ui {
class Quxiao;
}
class Quxiao : public QWidget
{
Q_OBJECT
public:
explicit Quxiao(QWidget *parent = nullptr);
~Quxiao();
signals:
void jump1();
private slots:
void on_btn1_clicked();
void on_btn2_clicked();
public:
void jump_slot1();
private:
Ui::Quxiao *ui;
};
#endif // QUXIAO_H
#ifndef DELU_H
#define DELU_H
#include <QWidget>
namespace Ui {
class Delu;
}
class Delu : public QWidget
{
Q_OBJECT
public:
explicit Delu(QWidget *parent = nullptr);
~Delu();
public slots:
void jump_slot();
private:
Ui::Delu *ui;
};
#endif // DELU_H
pro
面试题:
一.多态,虚函数,纯虚函数
多态是类的三大属性之一,分为静态多态和动态多态,静态多态是函数重载,动态多态又称动态绑定,在运行时去确定对象的类型和正确选择需要调用的函数,一般用于解决基类指针或引用派生类对象调用类中的重写的函数时出现的问题。多态意为一种形式多种状态,是父类指针或者引用,指向或初始化子类的对象,调用子类对父类重写的函数,进而展开子类的功能。
虚函数是函数前加上virtual,虚函数满足继承,父类中该函数时虚函数,继承到子类中,依然是虚函数,如果子类再被继承,“孙类还是虚函数”。
当类中有虚函数或者继承了虚函数时,类中自动添加一个虚指针,虚指针指向一个虚函数列表,列表中寻访指向虚函数的指针,实际上是一个函数指针数组。虚指针是一个指向函数指针数组的指针。
纯虚函数是当父类中虚函数被子类用来重写,但没有真正意义的时候,把父类中的虚函数写成纯虚函数,有纯虚函数的类是一个抽象类,只能被继承,无法实例化一个具体的对象。每个抽象类中至少有一个纯虚函数。当子类继承了父类的两个纯虚函数但只重写了一个纯虚函数是,就还是一个抽象类,无法实例化一个对象。
二.引用作为函数参数有哪些特点:
1.引用必须在函数定义时声明,且不能为NULL,必须引用一块已经存在的内存空间。
2通过引用传参可以避免复制大量数据,提高程序的执行效率。
3.通过引用传递参数,可以在函数内部对实参进行修改,从而改变原始值,不用返回值。
4.引用参数可以让函数接收不同类型的参数。
5.引用和目标占用同一块空间,在作为参数传递时,不会开辟新的空间,没有值传递和地址传递的区别