Qt网络编程

概述

Qt网络模块为我们提供了编写TCP / IP客户端和服务器的类。 它提供了较低级别的类,例如代表低级网络概念的QTcpSocket,QTcpServer和QUdpSocket,以及诸如QNetworkRequest,QNetworkReply和QNetworkAccessManager之类的高级类来执行使用通用协议的网络操作。 它还提供了诸如QNetworkConfiguration,QNetworkConfigurationManager和QNetworkSession等类,实现承载管理。

Qt网络编程类

要使用Qt网络类需要:
#include <QtNetwork>
要链接到Qt网络模块需要:
QT += network

名称空间

名称 描述
QSsl 定义Qt网络模块中SSL类公用的枚举

网络类

名称 描述
QAbstractNetworkCache The interface for cache implementations
QNetworkCacheMetaData Cache information
QHttpMultiPart Resembles a MIME multipart message to be sent over HTTP
QHttpPart Holds a body part to be used inside a HTTP multipart MIME message
QNetworkAccessManager Allows the application to send network requests and receive replies
QNetworkCookie 保存一个网络cookie
QNetworkCookieJar Implements a simple jar of QNetworkCookie objects
QNetworkDiskCache Very basic disk cache
QNetworkReply Contains the data and headers for a request sent with QNetworkAccessManager
QNetworkRequest Holds a request to be sent with QNetworkAccessManager
QNetworkConfigurationManager Manages the network configurations provided by the system
QNetworkConfiguration Abstraction of one or more access point configurations
QNetworkSession Control over the system's access points and enables session management for cases when multiple clients access the same access point
QAuthenticator Authentication object
QDnsDomainNameRecord Stores information about a domain name record
QDnsHostAddressRecord Stores information about a host address record
QDnsLookup Represents a DNS lookup
QDnsMailExchangeRecord Stores information about a DNS MX record
QDnsServiceRecord Stores information about a DNS SRV record
QDnsTextRecord Stores information about a DNS TXT record
QHostAddress IP address
QHostInfo Static functions for host name lookups
QNetworkDatagram The data and matadata of a UDP datagram
QNetworkAddressEntry Stores one IP address supported by a network interface, along with its associated netmask and broadcast address
QNetworkInterface Listing of the host's IP addresses and network interfaces
QNetworkProxy Network layer proxy
QNetworkProxyFactory Fine-grained proxy selection
QNetworkProxyQuery Used to query the proxy settings for a socket
QAbstractSocket The base functionality common to all socket types
QLocalServer Local socket based server
QLocalSocket Local socket
QSctpServer SCTP-based server
QSctpSocket SCTP socket
QTcpServer TCP-based server
QTcpSocket TCP 套接字
QUdpSocket UDP 套接字
QSslCertificate Convenient API for an X509 certificate
QSslCertificateExtension API for accessing the extensions of an X509 certificate
QSslCipher Represents an SSL cryptographic cipher
QSslConfiguration Holds the configuration and state of an SSL connection
QSslDiffieHellmanParameters Interface for Diffie-Hellman parameters for servers
QSslEllipticCurve Represents an elliptic curve for use by elliptic-curve cipher algorithms
QSslError SSL error
QSslKey Interface for private and public keys
QSslPreSharedKeyAuthenticator Authentication data for pre shared keys (PSK) ciphersuites
QSslSocket SSL encrypted socket for both clients and servers

HTTP和FTP协议的高级网络操作

网络访问API是用于执行常见网络操作的类的集合.API在所使用的特定操作和协议(例如,通过HTTP获取和发布数据)上提供了一个抽象层,并且仅暴露了一般或高级概念的类,函数和信号。

  • QNetworkRequest: 类用来代表一个网络请求,也用做与请求相关的信息的通用容器,例如请求的头信息和加密信息等.构造QNetwrokRequest时使用的URL决定了请求所使用的协议,目前Http,Ftp和本地文件URL支持上传和下载.

  • QNetworkAccessManager:协调各种网络操作,当我们构造一个QNetwrokRequest后就要使用QNetworkAccessManager来把它分发出去并使用信号槽来报告进度.QNetworkAccessManager还负责协调使用Cookie来存储客户端上的数据,身份验证请求和代理的使用.每个应用程序或库可以创建一个或多个QNetworkAccessManager实例来处理网络通信.

  • QNetworkReply:表示网络请求的回复.当发出一个网络请求后由QNetworkAccessManager创建QNetworkReply.由于QNetworkReply是QIODevice的子类,因此可以同步或异步处理回复; 即作为阻塞或非阻塞操作。QNetworkReply提供的信号可用于单独监控每个回复,也可以使用QNetworkAccessManager的信号来达到此目的.

QTcpScoket和QTcpServer

QUdpSocket

使用QHostInfo解析主机名称

网络代理

承载管理

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,061评论 19 139
  • 在QT的网路模块中提供了网络编程的相关接口来实现http的访问,其中包含了一些低级的类:QTcpSocket、QT...
    业余玩家阅读 3,579评论 0 1
  • 从三月份找实习到现在,面了一些公司,挂了不少,但最终还是拿到小米、百度、阿里、京东、新浪、CVTE、乐视家的研发岗...
    时芥蓝阅读 42,494评论 11 349
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,066评论 25 709
  • 昨天1月15号,是马頔的生日,一同学发状态称在她心里永远十八岁,每个人都有自己喜欢的人,玩命喜欢的人,你在我心里,...
    Beijing阅读 1,481评论 0 1

友情链接更多精彩内容