QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
server.cpp
HEADERS += \
server.h
FORMS += \
server.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
#ifndef SERVER_H
#define SERVER_H
#include <QWidget>
#include <QUdpSocket>
#include <QByteArray>
#include <QHostAddress>
#include <QString>
#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class Server; }
QT_END_NAMESPACE
class Server : public QWidget
{
Q_OBJECT
public:
Server(QWidget *parent = nullptr);
~Server();
QUdpSocket* serverSocket;
private:
Ui::Server *ui;
};
#endif // SERVER_H
#include "server.h"
#include "ui_server.h"
QString clientIP = "192.xxx.xxx.xxx"; //此处为IP地址
QString clientPort = "8888";
QString serverPort = "9999";
Server::Server(QWidget *parent): QWidget(parent), ui(new Ui::Server)
{
ui->setupUi(this);
ui->lineEdit->setText(clientIP);
ui->lineEdit_2->setText(clientPort);
ui->lineEdit_3->setText(serverPort);
serverSocket = new QUdpSocket(this);
//服务器接收信息
serverSocket->bind(serverPort.toInt()); //绑定服务器接收端口"9999"
connect(serverSocket,&QUdpSocket::readyRead,this,[=](){
qint64 size = serverSocket->pendingDatagramSize();
QByteArray array(size,0);
serverSocket->readDatagram(array.data(),size);
ui->textEdit_2->append(array);
});
//服务器发送信息
connect(ui->pushButton,&QPushButton::clicked,this,[=](){
serverSocket->writeDatagram(ui->textEdit->toPlainText().toUtf8(),QHostAddress(clientIP),clientPort.toInt());
});
}
Server::~Server()
{
delete ui;
}
就我记忆所及,我一直是 Ubuntu 的用户。我曾经转向过其他发行版,但最终还是一...
1. 异常现象 从 Intellij IDEA 2017.1 版本升级到当前最新版本?Intellij IDEA 20...
前言 我们从Web 2.0的随波逐流,Ajax的大放异彩说起,Struts2框架自己整合了对Aj...
最近一个项目中,有一个读取某个文件夹下所有文件的功能。使用了ThinkPHP + layu...
xslt支持的测试模式语句,用于条件判断,主要有:xsl:if和xsl:choose及其下的xsl:...
实例如下所示: mui.init(); mui.plusReady(function() { document.getElementBy...
百度ueditor组件,使用上传图片后,自动将上传图片显示在编辑器中,也就是插入了...
如何编写一个加法器? form action="./calculation.asp" input type="text" size...
%@ LANGUAGE="VBScript" % % 'Set file i/o constants. Const ForReading = 1 Co...
Asahi Linux 项目已公布了第一份进度报告,详细介绍了其为了将 Linux 移植到 App...