资源简介
QT TCP SOCKET SEND RECIEVE STRUCT SERVER CLIENT
看见这几个关键字了,应该知道是啥东西。

代码片段和文件信息
#include “dialogclient.h“
#include “ui_dialogclient.h“
#include
#include
#include
#include
DialogClient::DialogClient(QWidget *parent) :
QDialog(parent)
ui(new Ui::DialogClient)
{
ui->setupUi(this);
//端口验证
QIntValidator *vali = new QIntValidator();
vali->setRange(0 65535);
ui->lineEditPort->setValidator(vali);
//
ui->lineEditPort->setText(“2000“);
ui->lineEditIP->setText(“127.0.0.1“);
this->setLayout(ui->mainLayout);
//创建客户端
m_pTCPClient = new QTcpSocket();
//关联信号
connect(m_pTCPClient SIGNAL(connected()) this SLOT(OnSuccConnect()));
connect(m_pTCPClient SIGNAL(readyRead()) this SLOT(ReadStructDataAndShow()));
}
DialogClient::~DialogClient()
{
delete ui;
}
void DialogClient::on_pushButtonConnect_clicked()
{
int nPort = ui->lineEditPort->text().toInt();
QHostAddress address;
bool bres = address.setAddress(ui->lineEditIP->text());
//如果IP出错
if( ! bres )
{
QMessageBox::warning(this tr(“IP address error“) tr(“IP address is not correct!“));
return;
}
//开始连接
m_pTCPClient->connectToHost(address nPort);
}
void DialogClient::OnSuccConnect()
{
QMessageBox::information(this tr(“Connected“) tr(“Connect successed.“));
}
void DialogClient::ReadStructDataAndShow()
{
QString strMsg;
QByteArray dataArray = m_pTCPClient->readAll();
if(dataArray.length() != sizeof(NetData))
{
//长度不对
strMsg = tr(“Receive error struct length is %1 B recv length is %2 B“)
.arg(sizeof(NetData)).arg(dataArray.length());
qDebug()< //
return;
}
//接收长度正确
const NetData* pData = (NetData*)(dataArray.data());
//显示
QString strShow = tr(“NetData: \r\n“);
strShow += tr(“Length = %1\r\n“).arg(pData->length);
strShow += tr(“n1 = %1\r\n“).arg(pData->n1);
strShow += tr(“d1 = %1\r\n“).arg(pData->d1);
strShow += tr(“d2 = %1\r\n“).arg(pData->d2);
strShow += tr(“name = %1\r\n“).arg(pData->name);
//显示
ui->labelShow->setText(strShow);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-01-07 00:03 TestClient\
文件 397 2015-01-06 21:39 TestClient\TestClient.pro
文件 18267 2015-01-07 00:03 TestClient\TestClient.pro.user
文件 2295 2015-01-06 23:57 TestClient\dialogclient.cpp
文件 774 2015-01-06 23:55 TestClient\dialogclient.h
文件 2515 2015-01-06 23:58 TestClient\dialogclient.ui
文件 187 2015-01-06 21:38 TestClient\main.cpp
目录 0 2015-01-07 00:04 TestSrv\
文件 427 2015-01-06 22:21 TestSrv\TestSrv.pro
文件 18249 2015-01-07 00:03 TestSrv\TestSrv.pro.user
文件 583 2015-01-06 23:47 TestSrv\clientjobs.cpp
文件 538 2015-01-06 23:47 TestSrv\clientjobs.h
文件 3680 2015-01-06 23:53 TestSrv\dialogsrv.cpp
文件 1049 2015-01-06 23:51 TestSrv\dialogsrv.h
文件 2418 2015-01-06 23:45 TestSrv\dialogsrv.ui
文件 181 2015-01-06 21:38 TestSrv\main.cpp
相关资源
- 酒店管理系统基于Qt Creator5)
- vtk QT做的三维地质可视化系统2of2
- Qt局域网聊天软件
- Qt Creator opengl实现四元数鼠标控制轨迹
- QT局域网聊天系统(基于QT5.修改过)
- qt-电子点菜系统
- C 餐厅叫号系统(QT平)
- QT 实现文件下载
- qt图像处理
- QT,JPEG解码源代码(已完成)
- Qt 播放音频文件
- Fundamentals of Data Structure in C
- Qt 读取16进制的data文件
- MQTT+串口(usart)透传
- 易语言QQTEA算法源码
- VC工程转Qt工程文件的工具
- MQTT推送Demo
- 基于Linux、QT的视频监控系统的设计与
- Qt 百度地图 定位
- QT酷炫界面开发指南《QmlBook》
- Ubuntu下操作Excel,qt代码
- Qt图片浏览器 --基于Qt的Graphics View f
- qtnribbon2破解
- The Synthesis and Structure of a Novel Three-D
- Qt软件开发 完整项目代码
- Photoluminescence and photoabsorbance blue shi
- Coordination-resolved 4f binding energy shift
- MQTT_3.1protocol_Specific中文版
- Sub-wavelength surface structuring of NiTi all
- Gold-film coating assisted femtosecond laser f
评论
共有 条评论