本文整理汇总了C++中QAbstractSocket::proxy方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractSocket::proxy方法的具体用法?C++ QAbstractSocket::proxy怎么用?C++ QAbstractSocket::proxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractSocket
的用法示例。
在下文中一共展示了QAbstractSocket::proxy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QHttpSocketEngine
QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(const QHostAddress &address,
QAbstractSocket::SocketType socketType,
QObject *parent)
{
if (socketType != QAbstractSocket::TcpSocket)
return 0;
if (address == QHostAddress::LocalHost || address == QHostAddress::LocalHostIPv6)
return 0;
// find proxy info
QAbstractSocket *abstractSocket = qobject_cast<QAbstractSocket *>(parent);
if (!abstractSocket)
return 0;
QNetworkProxy proxy = abstractSocket->proxy();
if (proxy.type() == QNetworkProxy::DefaultProxy)
proxy = QNetworkProxy::applicationProxy();
if (proxy.type() != QNetworkProxy::HttpProxy)
return 0;
QHttpSocketEngine *engine = new QHttpSocketEngine(parent);
engine->setProxy(proxy);
return engine;
}
示例2: handleStateChanged
void SslTlsSocket::handleStateChanged()
{
/* Qt delivers the stateChanged() signal before the error() one.
That's a problem because we really want to provide a nice error message
to the user and QAbstractSocket::error() is not set yet by the time this
function executes. That's why we have to delay the first disconnected() signal. */
QAbstractSocket *sock = qobject_cast<QAbstractSocket *>(d);
Q_ASSERT(sock);
QString proxyMsg;
switch (sock->proxy().type()) {
case QNetworkProxy::NoProxy:
break;
case QNetworkProxy::HttpCachingProxy:
Q_ASSERT_X(false, "proxy detection",
"Qt should have returned a proxy capable of tunneling, but we got back an HTTP proxy.");
break;
case QNetworkProxy::FtpCachingProxy:
Q_ASSERT_X(false, "proxy detection",
"Qt should have returned a proxy capable of tunneling, but we got back an FTP proxy.");
break;
case QNetworkProxy::DefaultProxy:
proxyMsg = tr(" (via proxy %1)").arg(sock->proxy().hostName());
break;
case QNetworkProxy::Socks5Proxy:
proxyMsg = tr(" (via SOCKS5 proxy %1)").arg(sock->proxy().hostName());
break;
case QNetworkProxy::HttpProxy:
proxyMsg = tr(" (via HTTP proxy %1)").arg(sock->proxy().hostName());
break;
}
switch (sock->state()) {
case QAbstractSocket::HostLookupState:
emit stateChanged(Imap::CONN_STATE_HOST_LOOKUP, tr("Looking up %1%2...").arg(host,
sock->proxy().capabilities().testFlag(QNetworkProxy::HostNameLookupCapability) ?
proxyMsg : QString()));
break;
case QAbstractSocket::ConnectingState:
emit stateChanged(Imap::CONN_STATE_CONNECTING, tr("Connecting to %1:%2%3%4...").arg(
host, QString::number(port), startEncrypted ? tr(" (SSL)") : QString(),
sock->proxy().capabilities().testFlag(QNetworkProxy::TunnelingCapability) ?
proxyMsg : QString()));
break;
case QAbstractSocket::BoundState:
case QAbstractSocket::ListeningState:
break;
case QAbstractSocket::ConnectedState:
if (! startEncrypted) {
emit stateChanged(Imap::CONN_STATE_CONNECTED_PRETLS_PRECAPS, tr("Connected"));
} else {
emit stateChanged(Imap::CONN_STATE_SSL_HANDSHAKE, tr("Negotiating encryption..."));
}
break;
case QAbstractSocket::UnconnectedState:
case QAbstractSocket::ClosingState:
disconnectedMessage = tr("Socket is disconnected: %1").arg(sock->errorString());
delayedDisconnect->start();
break;
}
}