#include "server.h"
#include "ui_server.h"
#include<QHostAddress>
#include<QHostInfo>
Server::Server(QWidget *parent) :
QWidget(parent),
ui(new Ui::Server)
{
ui->setupUi(this);
this->port=10086;
this->server=NULL;
ui->let_IP->setText(GetIpv4Address());
ui->let_Port->setText(QString::number(port));
ui->let_IP->setEnabled(false);
ui->let_Port->setEnabled(false);
ui->let_Name->setText("Server");
ui->btn_Start->setEnabled(false);
ui->btn_Stop->setEnabled(false);
ui->btn_Send->setEnabled(false);
connect(ui->btn_Listen,SIGNAL(clicked()),this,SLOT(slotListen()));
connect(ui->btn_Start,SIGNAL(clicked()),this,SLOT(slotStart()));
connect(ui->btn_Stop,SIGNAL(clicked()),this,SLOT(slotStop()));
}
Server::~Server()
{
emit ui->btn_Stop->click();
delete ui;
}
QString Server::GetIpv4Address()
{
QString localHostName = QHostInfo::localHostName();
QHostInfo info = QHostInfo::fromName(localHostName);
foreach(QHostAddress address,info.addresses())
if(address.protocol() == QAbstractSocket::IPv4Protocol)
return address.toString();
}
void Server::slotListen()
{
server=new Listener(port,this,ui->let_Name->text());
connect(this,SIGNAL(listening()),this,SLOT(slotListening()));
connect(server,SIGNAL(timeout(qint64)),this,SLOT(slotTimeout(qint64)));
emit listening();
}
void Server::slotConnected(QString name)
{
ui->lbl_Status->setText("You are speaking with "+name);
ui->btn_Start->setEnabled(true);
ui->btn_Stop->setEnabled(true);
ui->btn_Send->setEnabled(true);
ui->let_Name->setEnabled(false);
connect(ui->btn_Send,SIGNAL(clicked()),this,SLOT(slotSendWords()));
connect(this,SIGNAL(sendWords(QString)),server->client,SLOT(slotSendWords(QString)));
connect(this,SIGNAL(getWords(QString)),this,SLOT(slotGetWords(QString)));
}
void Server::slotListening()
{
ui->lbl_Status->setText("Listening...");
ui->btn_Start->setEnabled(false);
ui->btn_Stop->setEnabled(false);
ui->btn_Send->setEnabled(false);
}
void Server::slotStart()
{
int dev=1;
if (ui->rbn_Out->isChecked()==true)
dev=0;
server->Start(dev);
}
void Server::slotStop()
{
server->camThread->terminate();
server->camThread->wait();
server->camThread->stop();
}
void Server::slotDisconnected()
{
ui->lbl_Status->setText("No Connection");
ui->btn_Start->setEnabled(false);
ui->btn_Stop->setEnabled(false);
ui->btn_Send->setEnabled(false);
}
void Server::slotGetWords(QString words)
{
ui->lwt_Words->addItem(words);
}
void Server::slotSendWords()
{
emit sendWords(ui->let_Name->text()+":"+ui->let_Words->text());
emit getWords(ui->let_Name->text()+":"+ui->let_Words->text());
ui->let_Words->clear();
}
void Server::slotShowImage(QImage image)
{
ui->lbl_Image->setPixmap(QPixmap::fromImage(image));
}
void Server::slotTimeout(qint64 size)
{
ui->lbl_Speed->setText("Speed:"+QString::number((int)size/1024)+"kb/s");
size=0;
}
Victor_YXL
- 粉丝: 4
- 资源: 23
最新资源
- 基于51单片机LCD1602显示的一个万年历+可调时钟(含原理图)
- Day-06 Vue222222222
- OREO:离线增强型大型语言模型多步推理优化方法
- iClient3D for Cesium 加载shp数据并拉伸为白模
- flowable-demo-master
- 大模型的稀疏激活方法及其高效推理应用研究:基于dReLU激活函数
- au2024_113102-1.zip
- 大规模语言模型在不同NLP任务中的提示工程技术综述
- 廖鹏盛 - 时代进行曲.zip
- 土地利用/土地覆盖数据(蚌埠市)
- Matlab实现VMD-TCN-BiLSTM变分模态分解结合时间卷积双向长短期记忆神经网络多变量光伏功率时间序列预测(含完整的程序,GUI设计和代码详解)
- LLM-Select: Feature Selection with Large Language Models
- Matlab实现RP-LSTM-Attention递归图优化长短期记忆神经网络注意力机制的数据分类预测(含完整的程序,GUI设计和代码详解)
- Another Redis Desktop软件
- 鲸鱼优化算法(WOA)文章复现:《改进鲸鱼优化算法在机械臂时间最优轨迹规划的应用-赵晶》 策略为:Tent混沌初始化种群+非线性权重改进位置更新+非线性概率转-IWOA 复现内容包
- 页岩油四性潜力层判识工具
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
前往页