1 Star 0 Fork 0

小邓/client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
client_socket.cpp 4.05 KB
一键复制 编辑 原始数据 按行查看 历史
小邓 提交于 2024-07-07 01:26 +08:00 . 清理到部分不必要的输出和注释
#include "client_socket.h"
#include "ui_client_socket.h"
client_socket::client_socket(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::client_socket)
{
ui->setupUi(this);
initConfig();
m_connect();
connect(&m_cliSocket,&my_tcpsocket::connected,this,&client_socket::showConnect);
connect(&m_cliSocket,&my_tcpsocket::readyRead,&m_cliSocket,&my_tcpsocket::receiveMsg);
}
client_socket::~client_socket()
{
delete ui; // 释放 ui 对象
// delete m_pFileSystem; // 释放 FileSystem 对象
delete m_pServerFileSystem; // 释放 serverFileSystem 对象
// delete mainWidget; // 释放 OperateWidget 对象,注意 mainWidget 不是 client_socket 的子对象
}
void client_socket::initConfig()
{
QFile file(":/client.config");
if(file.open(QIODevice::ReadOnly))
{
QByteArray data = file.readAll();
QString strData = data.toStdString().c_str();
strData.replace("\n"," ");
QStringList strlist = strData.split(" ");
m_strIP = strlist[0];
m_usPort = strlist[1].toUInt();
file.close();
}
else
{
QMessageBox::critical(this,"open config","open config failed");
}
}
void client_socket::m_connect()
{
m_cliSocket.connectToHost(QHostAddress(m_strIP),m_usPort);
}
client_socket &client_socket::getInstance()
{
static client_socket instance;
return instance;
}
my_tcpsocket &client_socket::getTcpSocket()
{
return m_cliSocket;
}
QString client_socket::getM_userRootPath()
{
return m_userRootPath;
}
QString client_socket::getM_serverRootPath()
{
return m_serverRootPath;
}
void client_socket::setM_userRootPath(QString rootPath)
{
m_userRootPath = rootPath;
}
void client_socket::setM_serverRootPath(QString rootPath)
{
m_serverRootPath = rootPath;
}
QString client_socket::getM_userID()
{
return m_userID;
}
QString client_socket::getM_rootPath()
{
return m_rootPath;
}
void client_socket::setM_rootPath(QString rootPath)
{
m_rootPath=rootPath;
}
OperateWidget *&client_socket::get_mainWidget()
{
return mainWidget;
}
// FileSystem *&client_socket::getM_pFileSystem()
// {
// return m_pFileSystem;
// }
serverFileSystem *&client_socket::getM_pServerFileSystem()
{
return m_pServerFileSystem;
}
QString client_socket::getStrIP()
{
return m_strIP;
}
quint16 client_socket::getUSPort()
{
return m_usPort;
}
void client_socket::closeEvent(QCloseEvent *event)
{
// 进行持久化操作
// qDebug()<<"持久化";
if (mainWidget && mainWidget->get_ChatWidget())
{
// qDebug()<<"chat_history";
mainWidget->get_ChatWidget()->chat_history_persisitence();
}
// 确保资源被释放后,允许窗口正常关闭
event->accept();
}
void client_socket::showConnect()
{
QMessageBox::information(NULL,"连接服务器","连接服务器成功");
}
void client_socket::on_register_2_clicked()
{
QString ID = ui->account->text() ;
QString pwd = ui->pwd->text();
if(!ID.isEmpty() && !pwd.isEmpty())
{
PDU* pdu = mkPDU(64);
pdu->uiMsgType=MSG_TYPE::MSG_TYPE_LOGIN_REGISTER_REQUEST;
memcpy(pdu->msg,ID.toStdString().c_str(),32);
memcpy(pdu->msg+32,pwd.toStdString().c_str(),32);
m_cliSocket.write((char*)pdu,pdu->uiPduLen );
free(pdu);
pdu=NULL;
}
else
{
QMessageBox::warning(this,"注册","ID或密码不能为空");
}
}
void client_socket::on_login_clicked()
{
QString ID = ui->account->text() ;
QString pwd = ui->pwd->text();
if(!ID.isEmpty() && !pwd.isEmpty())
{
PDU* pdu = mkPDU(64);
pdu->uiMsgType=MSG_TYPE::MSG_TYPE_LOGIN_IN_REQUEST;
memcpy(pdu->msg,ID.toStdString().c_str(),32);
memcpy(pdu->msg+32,pwd.toStdString().c_str(),32);
m_cliSocket.write((char*)pdu,pdu->uiPduLen);
m_userID=ID;
free(pdu);
pdu=NULL;
}
else
{
QMessageBox::warning(this,"登录","ID或密码不能为空");
}
}
void client_socket::on_logout_clicked()
{
}
void client_socket::on_forget_clicked()
{
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xiao-deng-a/client.git
git@gitee.com:xiao-deng-a/client.git
xiao-deng-a
client
client
master

搜索帮助