当前位置: 首页>>代码示例>>C++>>正文


C++ QAbstractSocket::state方法代码示例

本文整理汇总了C++中QAbstractSocket::state方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractSocket::state方法的具体用法?C++ QAbstractSocket::state怎么用?C++ QAbstractSocket::state使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QAbstractSocket的用法示例。


在下文中一共展示了QAbstractSocket::state方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
    }
}
开发者ID:ChristopherCotnoir,项目名称:trojita,代码行数:60,代码来源:IODeviceSocket.cpp

示例2: incomingConnection

void XmlRpcServer::incomingConnection( int socketDescriptor )
{
#ifdef DEBUG_XMLRPC
    qDebug() << this << "new incoming connection";
#endif

    QAbstractSocket * s = NULL;
#ifndef QT_NO_OPENSSL
    if ( sslParams != NULL && !sslParams->certificate.isNull() )
        {
            s = new QSslSocket( this );
            s->setSocketDescriptor( socketDescriptor );

            ((QSslSocket *)s)->setLocalCertificate( sslParams->certificate );
            ((QSslSocket *)s)->setPrivateKey( sslParams->privateKey );
            ((QSslSocket *)s)->setCaCertificates( sslParams->ca );
        }
    else
        {
            s = new QTcpSocket( this );
            s->setSocketDescriptor( socketDescriptor );
        }
#else
      s = new QTcpSocket( this );
      s->setSocketDescriptor( socketDescriptor );
#endif

      Q_ASSERT( s->state() == QAbstractSocket::ConnectedState );
      connect( s, SIGNAL(disconnected()), this, SLOT(slotSocketDisconnected()) );

      HttpServer * p = new HttpServer( s );
      connect( p, SIGNAL(protocolTimeout(Protocol*)),
               this, SLOT(slotProtocolTimeout(Protocol*)) );
      connect( p, SIGNAL(parseError(HttpServer*)),
               this, SLOT(slotParseError(HttpServer*)) );
      connect( p, SIGNAL(requestReceived(HttpServer*, const QHttpRequestHeader&, const QByteArray&)),
               this, SLOT(slotRequestReceived(HttpServer*, const QHttpRequestHeader&, const QByteArray&)) );
      connect( p, SIGNAL(replySent(HttpServer*)),
               this, SLOT(slotReplySent(HttpServer*)) );
}
开发者ID:yohe,项目名称:qtxmlrpc-fork,代码行数:40,代码来源:xmlrpcserver.cpp

示例3: isDead

bool SslTlsSocket::isDead()
{
    QAbstractSocket *sock = qobject_cast<QAbstractSocket *>(d);
    Q_ASSERT(sock);
    return sock->state() != QAbstractSocket::ConnectedState;
}
开发者ID:ChristopherCotnoir,项目名称:trojita,代码行数:6,代码来源:IODeviceSocket.cpp


注:本文中的QAbstractSocket::state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。