9_28代码实现登录框 注释

注释:

.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget> // 防止头文件重复包含

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }  
//Ui表示命名空间的名称
//{ class Widget; } :表示在Ui命名空间中声明一个其他文件midget的类
QT_END_NAMESPACE
//QT_BEGIN_NAMESPACE  QT_END_NAMESPACE :用于管理QT命名空间的宏,避免命名冲突


class Widget : public QWidget
//对自定义类的声明,公共继承了QWidget QWidget封装了有关图形化界面的相关功能
{
    Q_OBJECT  //宏 表示信号与曹的元素对象,

public:
    Widget(QWidget *parent = nullptr); //构造函数的声明
    ~Widget(); //析构函数的声明   虚析构函数

private:
    Ui::Widget *ui;   //成员指针
};
#endif // WIDGET_H

main.cpp

#include "widget.h"
//文件包含,自定义的头文件,该头文件包含了图形化界面类
#include <QApplication>//包含应用程序的头文件

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);//应用成员类实例化对象,调用有参构造
    Widget w;//使用自定义的类调用无参构造在栈区构造一个界面对象
    w.show(); //调用对象的成员函数,将界面展示出来
    return a.exec(); //应用程序类对象,调用应用程序的成员函数,保证界面不被关闭,轮寻等待界面上的时间发生
    
}

.cpp

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)  //构造函数定义
    : QWidget(parent)  //在子类的初始化列表中显示调用父类的有参构造,来完成对子类从父类的继承
    , ui(new Ui::Widget) //给自己的类中的指针成员实例化空间
{
    ui->setupUi(this); //将UI界面的组件展示在this界面上
}

Widget::~Widget()  //析构函数的定义
{
    delete ui;  //释放UI界面的组件空间
}

.pro

QT       += core gui
#引用的QT的类库,core:表示核心库 gui:表示图形优化库
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
#greaterThan:这是QT的内置函数,用于比较两个值  QT_MAJOR_VERSION:是个宏定义表示QT版本号  4:在上下文中表示QT的主板本号 
#QT:指定要链接的QT模版  widgets:QT模版用于提供创建图形用户界面的功能
#整体:表示如果QT的版本大于4,将widgets的模版添加到项目中
CONFIG += c++11 #表示支持C++的版本号为11版本

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
#表示 是一种用于提高代码质量和维护性的编译指令,通过启用对已弃用功能的警告,帮助开发者及时更新和维护代码。
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \        #实现项目的管理
    main.cpp \      #表示要管理的源文件
    widget.cpp

HEADERS += \        #管理头文件
    widget.h        #管理的头文件

FORMS += \          #管理所以的UI文件
    widget.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

登录框

#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{


    this->setFixedSize(400,500);//设置当前界面尺寸
   // this->setStyleSheet("D:/tubiao/640.gif");//这种背景颜色为粉色
    QLabel *ptr3 = new QLabel(this);
        ptr3->resize(400,500);
        ptr3->move(0,0);
        QMovie *movie = new QMovie("D:/tubiao/640.gif");
        ptr3->setMovie(movie);
        movie->start();
        ptr3->setScaledContents(true);
   //使用QIcon实例化一个对象
    QIcon icon("D:/tubiao/icon_6dj6gprvzoq/icon_6dj6gprvzoq/tubiao-_4.png");
    this->setWindowIcon(icon);//跟换图标

    this->setWindowTitle("QQ"); //跟换窗口标题
    QPushButton * btn1=new QPushButton;
    QPushButton *btn2=new QPushButton(this);
    QPushButton *btn3=new QPushButton("登录",this);
    QPushButton *btn4=new QPushButton("注册",this);

    btn1->setParent(this); // 将当前界面设置成组件的父组件
  //  btn1->setStyleSheet("clor:white;background:skyblue;border-radius:10px;");
    btn1->setText("账号:");   //设置按钮文本内容
    btn1->resize(60,35);    //  重新设置尺寸
    btn1->move(50,150);        //移动当前按钮
  //  btn2->setStyleSheet("clor:white;background:skyblue;border-radius:10px;");
    btn2->setText("密码:");   //设置按钮文本内容
    btn2->resize(btn1->size());    //  重新设置尺寸
    btn2->move(50,200);   //移动当前按钮

   // btn3->setStyleSheet("clor:white;background:skyblue;");
    btn3->resize(btn2->size());    //  重新设置尺寸
    btn3->move(100,250);   //移动当前按钮
    btn4->resize(btn3->size());    //  重新设置尺寸
    btn4->move(200,250);   //移动当前按钮
    QLineEdit *edit1=new QLineEdit(this);
    QLineEdit *edit2=new QLineEdit(this);
    edit1->resize(200,35);
    edit2->resize(200,35);
    edit1->setPlaceholderText("请输入账号");

    edit2->setPlaceholderText("请输入密码");
    edit2->setEchoMode(QLineEdit::Password);
    edit1->move(110,150);
    edit2->move(110,200);






}

Widget::~Widget()
{
}

Java Executors架是Java中用于管理线程池的一个工具类,它提供了一组便捷的方法来创建和管理线程池,可以帮助程序员更有效地使用线程池来实现多线程编程。 以下是一个简单的Java Executors架的实现,带有注释: ``` import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ExecutorsDemo { public static void main(String[] args) { // 创建一个固定大小的线程池,线程池中的线程数始终为5个 ExecutorService executorService = Executors.newFixedThreadPool(5); // 循环提交任务 for (int i = 0; i < 10; i++) { // 提交任务到线程池 executorService.submit(new Task(i)); } // 关闭线程池 executorService.shutdown(); } // 任务类 static class Task implements Runnable { int taskId; public Task(int taskId) { this.taskId = taskId; } @Override public void run() { System.out.println("Task " + taskId + " is running on Thread " + Thread.currentThread().getName()); } } } ``` 上面的代码创建了一个固定大小为5的线程池,并循环提交10个任务到线程池中。每个任务都是一个简单的Runnable对象,它只是打印一条消息来表示它正在运行。最后,线程池被关闭以释放系统资源。 注释中包含了一些关键的点,例如如何创建线程池、如何提交任务、如何关闭线程池等。在实际开发中,使用Java Executors架可以帮助程序员更轻松地管理线程池,从而提高程序的并发性和性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值