资源简介
该系统采用qt编写,分为client端,server端与employee端,采用udpsocket实现通讯,能够实现取号,叫号与经理检查的功能
代码片段和文件信息
#include “client.h“
#include “ui_client.h“
client::client(QWidget *parent) :
QMainWindow(parent)
ui(new Ui::client)
{
ui->setupUi(this);
initSocket();
connect(ui->pushButton_Ordinary SIGNAL(clicked()) this SLOT(slot_ordinary()));
connect(ui->pushButton_VIP SIGNAL(clicked()) this SLOT(slot_VIP()));
connect(ui->closeSIGNAL(clicked())thisSLOT(close()));
timer = new QTimer(this);
timer->start(500);
connect(timer SIGNAL(timeout()) this SLOT(displayTime()));
}
client::~client()
{
delete ui;
}
//初始化套接字
void client ::initSocket()
{
udpSocket = new QUdpSocket(this);
udpSocket->bind(QHostAddress::LocalHost 2222);
connect(udpSocket SIGNAL(readyRead())this SLOT(readPendingDatagrams()));
}
void client::slot_ordinary()
{
//send a ordinary_request to server
int fl=0;
QByteArray datagram;
datagram=“1“;
fl= udpSocket->writeDatagram(datagram.data()datagram.size()QHostAddress::LocalHost3333);
if(fl==-1)
{
ui->label_Ordinary->setText(“error“);
}
else if(fl>0)
{
ui->label_Ordinary->setText(“please wait...“);
}
}
void client::slot_VIP()
{
//send a VIP_request to server
int fl=0;
QByteArray datagram;
datagram=“2“;
fl= udpSocket->writeDatagram(datagram.data()datagram.size()QHostAddress::LocalHost3333);
if(fl==-1)
{
ui->label_VIP->setText(“error“);
}
else if(fl>0)
{
ui->label_VIP->setText(“please wait...“);
}
}
//显示时间
void client ::displayTime(){
QDateTime dateTime;
QString currentTime;
dateTime = QDateTime::currentDateTime();
currentTime = dateTime.toString(“yyyy-MM-dd hh:mm:ss“);
ui->label_time->setText(currentTime);
}
//读等待的数据报
void client ::readPendingDatagrams()
{
while (udpSocket->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(udpSocket->pendingDatagramSize());
udpSocket->readDatagram(datagram.data() datagram.size());
processTheDatagram(datagram);//接收显示
}
}
void client ::processTheDatagram(QByteArray datagram)
{
QString ju=datagram;
if(ju.startsWith(“1;“))
{
//ordinary
QString f = “;“;
int a = ju.indexOf(f3);
QString tmp = ju.mid(2a-2);
int order = tmp.toInt();
QString tmp1 = ju.mid(a+1);
int number = tmp1.toInt();
QString i=QString::fromUtf8(“普通客户您好,您前面有“);
QString j=QString::fromUtf8(“人排队。“);
ui->label_Ordinary->setText(QString(“%1%2%3“).arg(i).arg(number).arg(j));
QString k=QString::fromUtf8(“取号成功,您的号码是“);
QString m=QString::fromUtf8(“号。“);
ui->lineEdit_Ordinary->setText(QString(“%1%2%3“).arg(k).arg(order).arg(m));
}
else if(ju.startsWith(“2;“))
{
//VIP
QString f = “;“;
int a = ju.indexOf(f3);
QString tmp = ju.mid(2a-2);
int order = tmp.toInt();
QString tmp1 = ju.mid(a+1);
int nu
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4312 2016-07-10 10:23 bank\demo_client\client.cpp
文件 582 2016-07-10 10:19 bank\demo_client\client.h
文件 314300 2016-07-10 10:23 bank\demo_client\client.o
文件 5976 2016-07-09 19:54 bank\demo_client\client.ui
文件 278889 2016-07-27 19:15 bank\demo_client\debug\client.o
文件 1300180 2016-07-27 19:15 bank\demo_client\debug\demo_client.exe
文件 200471 2016-07-27 19:15 bank\demo_client\debug\logdia.o
文件 205835 2016-07-27 19:15 bank\demo_client\debug\main.o
文件 2642 2016-07-27 19:15 bank\demo_client\debug\moc_client.cpp
文件 217686 2016-07-27 19:15 bank\demo_client\debug\moc_client.o
文件 2359 2016-07-27 19:15 bank\demo_client\debug\moc_logdia.cpp
文件 126527 2016-07-27 19:15 bank\demo_client\debug\moc_logdia.o
文件 628458 2016-07-10 10:23 bank\demo_client\demo_client
文件 329 2016-07-09 19:54 bank\demo_client\demo_client.pro
文件 14477 2016-07-29 10:16 bank\demo_client\demo_client.pro.user
文件 10712 2016-07-10 12:47 bank\demo_client\demo_client.pro.user.1.3
文件 453 2016-07-07 16:42 bank\demo_client\logdia.cpp
文件 340 2016-07-07 16:42 bank\demo_client\logdia.h
文件 234540 2016-07-07 16:53 bank\demo_client\logdia.o
文件 667 2016-07-07 16:42 bank\demo_client\logdia.ui
文件 290 2016-07-07 16:52 bank\demo_client\main.cpp
文件 241692 2016-07-10 10:19 bank\demo_client\main.o
文件 5804 2016-07-28 09:58 bank\demo_client\Makefile
文件 6290 2016-07-28 09:58 bank\demo_client\Makefile.Debug
文件 6392 2016-07-28 09:58 bank\demo_client\Makefile.Release
文件 2552 2016-07-10 10:19 bank\demo_client\moc_client.cpp
文件 251292 2016-07-10 10:19 bank\demo_client\moc_client.o
文件 2276 2016-07-07 16:53 bank\demo_client\moc_logdia.cpp
文件 144732 2016-07-07 16:53 bank\demo_client\moc_logdia.o
文件 8390 2016-07-10 08:53 bank\demo_client\ui_client.h
............此处省略104个文件信息
评论
共有 条评论