QNetworkProxyFactory 类

QNetworkProxyFactory class provides fine-grained proxy selection. 更多...

Header: #include <QNetworkProxyFactory>
qmake: QT += network
Since: Qt 4.5

公共函数

QNetworkProxyFactory ()
virtual ~QNetworkProxyFactory ()
virtual QList<QNetworkProxy> queryProxy (const QNetworkProxyQuery & query = QNetworkProxyQuery()) = 0

静态公共成员

QList<QNetworkProxy> proxyForQuery (const QNetworkProxyQuery & query )
void setApplicationProxyFactory (QNetworkProxyFactory * factory )
void setUseSystemConfiguration (bool enable )
QList<QNetworkProxy> systemProxyForQuery (const QNetworkProxyQuery & query = QNetworkProxyQuery())
bool usesSystemConfiguration ()

详细描述

QNetworkProxyFactory class provides fine-grained proxy selection.

QNetworkProxyFactory is an extension to QNetworkProxy ,允许应用程序对使用哪些代理服务器有更细粒度的控制,取决于请求代理的套接字。例如,这允许应用程序根据协议或目标主机名应用不同的设置。

QNetworkProxyFactory can be set globally for an application, in which case it will override any global proxies set with QNetworkProxy::setApplicationProxy (). If set globally, any sockets created with Qt will query the factory to determine the proxy to be used.

A factory can also be set in certain frameworks that support multiple connections, such as QNetworkAccessManager . When set on such object, the factory will be queried for sockets created by that framework only.

系统代理

可以把工厂配置为使用系统代理的设置。调用 setUseSystemConfiguration () 函数采用 true 以启用此行为,或 false 以禁用此行为。

同样,可以使用工厂以直接查询系统代理通过调用其 systemProxyForQuery () 函数。

警告: 从属用户系统配置,在某些平台使用的系统代理特征可能会受到限制。 systemProxyForQuery () 文档编制包含那些受影响平台的局限性列表。

成员函数文档编制

QNetworkProxyFactory:: QNetworkProxyFactory ()

创建 QNetworkProxyFactory 对象。

Since QNetworkProxyFactory is an abstract class, you cannot create objects of type QNetworkProxyFactory directly.

[virtual] QNetworkProxyFactory:: ~QNetworkProxyFactory ()

销毁 QNetworkProxyFactory 对象。

[static] QList < QNetworkProxy > QNetworkProxyFactory:: proxyForQuery (const QNetworkProxyQuery & query )

此函数接受查询请求 query , examines the details of the type of socket or request and returns a list of QNetworkProxy objects that indicate the proxy servers to be used, in order of preference.

[pure virtual] QList < QNetworkProxy > QNetworkProxyFactory:: queryProxy (const QNetworkProxyQuery & query = QNetworkProxyQuery())

此函数接受查询请求 query , examines the details of the type of socket or request and returns a list of QNetworkProxy objects that indicate the proxy servers to be used, in order of preference.

当重实现此类时,小心至少要返回一元素。

若无法确定更好的代理替代方案,使用 QNetworkProxy::DefaultProxy , which tells the code querying for a proxy to use a higher alternative. For example, if this factory is set to a QNetworkAccessManager object, DefaultProxy will tell it to query the application-level proxy settings.

If this factory is set as the application proxy factory, DefaultProxy and NoProxy will have the same meaning.

[static] void QNetworkProxyFactory:: setApplicationProxyFactory ( QNetworkProxyFactory * factory )

Sets the application-wide proxy factory to be factory . This function will take ownership of that object and will delete it when necessary.

The application-wide proxy is used as a last-resort when all other proxy selection requests returned QNetworkProxy::DefaultProxy 。例如, QTcpSocket objects can have a proxy set with QTcpSocket::setProxy , but if none is set, the proxy factory class set with this function will be queried.

If you set a proxy factory with this function, any application level proxies set with QNetworkProxy::setApplicationProxy will be overridden, and usesSystemConfiguration () 会返回 false .

另请参阅 QNetworkProxy::setApplicationProxy (), QAbstractSocket::proxy (),和 QAbstractSocket::setProxy ().

[static] void QNetworkProxyFactory:: setUseSystemConfiguration ( bool enable )

启用特定平台代理设置的使用,且只使用那些。见 systemProxyForQuery () 了解更多信息。

调用此函数采用 enable 设为 true 重置任何代理或 QNetworkProxyFactory 已经设置。

注意: systemProxyForQuery () 文档编制,了解使用系统代理的相关局限性列表。

This function was introduced in Qt 4.6.

[static] QList < QNetworkProxy > QNetworkProxyFactory:: systemProxyForQuery (const QNetworkProxyQuery & query = QNetworkProxyQuery())

此函数接受查询请求 query , examines the details of the type of socket or request and returns a list of QNetworkProxy objects that indicate the proxy servers to be used, in order of preference.

This function can be used to determine the platform-specific proxy settings. This function will use the libraries provided by the operating system to determine the proxy for a given connection, if such libraries exist. If they don't, this function will just return a QNetworkProxy of type QNetworkProxy::NoProxy .

On Windows, this function will use the WinHTTP DLL functions. Despite its name, Microsoft suggests using it for all applications that require network connections, not just HTTP. This will respect the proxy settings set on the registry with the proxycfg.exe tool. If those settings are not found, this function will attempt to obtain Internet Explorer's settings and use them.

On macOS , this function will obtain the proxy settings using the SystemConfiguration framework from Apple. It will apply the FTP, HTTP and HTTPS proxy configurations for queries that contain the protocol tag "ftp", "http" and "https", respectively. If the SOCKS proxy is enabled in that configuration, this function will use the SOCKS server for all queries. If SOCKS isn't enabled, it will use the HTTPS proxy for all TcpSocket and UrlRequest queries.

On other systems, this function will pick up proxy settings from the "http_proxy" environment variable. This variable must be a URL using one of the following schemes: "http", "socks5" or "socks5h".

局限性

These are the limitations for the current version of this function. Future versions of Qt may lift some of the limitations listed here.

  • On macOS , this function will ignore the Proxy Auto Configuration settings, since it cannot execute the associated ECMAScript code.
  • On Windows platforms, this function may take several seconds to execute depending on the configuration of the user's system.

[static] bool QNetworkProxyFactory:: usesSystemConfiguration ()

返回是否已启用特定平台代理设置的使用。

This function was introduced in Qt 5.8.