基于C++的IM即时通讯系统之登录客户端(一)

8 篇文章 0 订阅
  • QT creator 4.11.0 + C++ + 代码 = IM客户端
  • 手写代码做界面。
  • 客户端。
  • 代码地址:XiaIM

流程

  • 新建一个Qt Widgets Application项目。

  • 新建一个类,取名为login。

  • 界面
    在这里插入图片描述

  • 代码如下:

login.h

#ifndef LOGIN_H
#define LOGIN_H

#include <QMainWindow>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <string>
#include <QTextCodec>

class CLogin : public QMainWindow
{
    Q_OBJECT
public:
    explicit CLogin(QMainWindow *parent = nullptr);
    ~CLogin();

public slots:
    bool Login();

private:
    QPushButton *m_pButtonLogin;
    QLabel *m_pLabelUserName;
    QLabel *m_pLabelpassword;
    QLineEdit *m_pLineEditName;
    QLineEdit *m_pLineEditPwd;
};
#endif // LOGIN_H

login.cpp

#include "login.h"
CLogin::CLogin(QMainWindow *parent)
{
    this->resize(QSize(400, 300));

    QPalette palette;
    palette.setBrush(QPalette::Background, QBrush(QPixmap("../IMClient/resource/pictures/login_bg.jpg")));
    this->setPalette(palette);

    m_pLabelUserName = new QLabel(this);
    m_pLabelUserName->move(120, 80);
    m_pLabelUserName->setText(QStringLiteral("用户名:"));
    m_pLineEditName = new QLineEdit(this);
    m_pLineEditName->move(190, 80);
    m_pLineEditName->setPlaceholderText(QStringLiteral("请输入用户名"));

    m_pLabelpassword = new QLabel(this);
    m_pLabelpassword->move(120, 130);
    m_pLabelpassword->setText(QStringLiteral("密码:"));
    m_pLineEditPwd = new QLineEdit(this);
    m_pLineEditPwd->move(190, 130);
    m_pLineEditPwd->setPlaceholderText(QStringLiteral("请输入密码"));
    m_pLineEditPwd->setEchoMode(QLineEdit::Password);

    m_pButtonLogin = new QPushButton(this);
    m_pButtonLogin->move(150, 200);
    m_pButtonLogin->setText(QStringLiteral("登录"));

    connect(m_pButtonLogin, &QPushButton::clicked, this, &CLogin::Login);
}

CLogin::~CLogin()
{
    delete this;
}

bool CLogin::Login()
{
    QString username = m_pLineEditName->text();
    QString password = m_pLineEditPwd->text();
    printf("%s login success\n", username.toStdString().data());
    return true;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值