代码拉取完成,页面将自动刷新
#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()
{
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。