Как узнать о состоянии соединения с прокси, используя QNetworkProxy?



  • Иногда, используя прокси, получаю отказ в соединении с целевым сервером и закрытие соединения с прокси.
    При этом никакого сигнала от QNetworkAccessManager или QNetworkReply не исходит.
    Через снифер видно, что прокси-сервер завершил соединение, но кодом этого поймать не могу.
    Как узнать о закрытии соединения с прокси-сервером?

    #include <QCoreApplication>
    #include <QObject>
    #include <QNetworkAccessManager>
    #include <QNetworkRequest>
    #include <QNetworkProxy>
    #include <QNetworkReply>
    #include <QTimer>
    #include <QAuthenticator>
     
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
     
        QNetworkAccessManager *manager = new QNetworkAccessManager;
     
        QNetworkProxy netProxy;
        netProxy.setType(QNetworkProxy::ProxyType::Socks5Proxy);
        netProxy.setHostName("45.55.27.161");
        netProxy.setPort(1080);
        manager->setProxy(netProxy);
     
        QNetworkReply *reply = manager->get(QNetworkRequest(QUrl("https://yandex.ru/internet/")));
     
        QObject::connect(manager, &QNetworkAccessManager::authenticationRequired, [=](QNetworkReply *reply, QAuthenticator *authenticator){qDebug() << "authenticationRequired";});
        QObject::connect(manager, &QNetworkAccessManager::encrypted, [=](QNetworkReply *reply){qDebug() << "encrypted";});
        QObject::connect(manager, &QNetworkAccessManager::finished, [=](QNetworkReply *reply){qDebug() << "finished";});
        QObject::connect(manager, &QNetworkAccessManager::networkAccessibleChanged, [=](QNetworkAccessManager::NetworkAccessibility accessible){qDebug() << "networkAccessibleChanged";});
        QObject::connect(manager, &QNetworkAccessManager::preSharedKeyAuthenticationRequired, [=](QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator){qDebug() << "preSharedKeyAuthenticationRequired";});
        QObject::connect(manager, &QNetworkAccessManager::proxyAuthenticationRequired, [=](const QNetworkProxy &proxy, QAuthenticator *authenticator){qDebug() << "proxyAuthenticationRequired";});
        QObject::connect(manager, &QNetworkAccessManager::sslErrors, [=](QNetworkReply *reply, const QList<QSslError> &errors){qDebug() << "sslErrors";});
     
        QObject::connect(manager, &QNetworkAccessManager::destroyed, [=](QObject *obj = nullptr){qDebug() << "destroyed";});
        QObject::connect(manager, &QNetworkAccessManager::objectNameChanged, [=](const QString &objectName){qDebug() << "objectNameChanged";});
     
        QObject::connect(manager, &QNetworkAccessManager::networkSessionConnected, [=](){qDebug() << "networkSessionConnected";});
     
     
     
        QObject::connect(reply, &QNetworkReply::downloadProgress, [=](qint64 bytesReceived, qint64 bytesTotal){qDebug() << "downloadProgress";});
        QObject::connect(reply, &QNetworkReply::encrypted, [=](){qDebug() << "encrypted";});
        QObject::connect(reply, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), [=](QNetworkReply::NetworkError code){qDebug() << "error" << code;});
        QObject::connect(reply, &QNetworkReply::finished, [=](){qDebug() << "finished";});
        QObject::connect(reply, &QNetworkReply::metaDataChanged, [=](){qDebug() << "metaDataChanged";});
        QObject::connect(reply, &QNetworkReply::preSharedKeyAuthenticationRequired, [=](QSslPreSharedKeyAuthenticator *authenticator){qDebug() << "preSharedKeyAuthenticationRequired";});
        QObject::connect(reply, &QNetworkReply::redirectAllowed, [=](){qDebug() << "redirectAllowed";});
        QObject::connect(reply, &QNetworkReply::redirected, [=](const QUrl &url){qDebug() << "redirected";});
        QObject::connect(reply, &QNetworkReply::sslErrors, [=](const QList<QSslError> &errors){qDebug() << "sslErrors";});
        QObject::connect(reply, &QNetworkReply::uploadProgress, [=](qint64 bytesSent, qint64 bytesTotal){qDebug() << "uploadProgress";});
     
        QObject::connect(reply, &QNetworkReply::aboutToClose, [=](){qDebug() << "aboutToClose";});
        QObject::connect(reply, &QNetworkReply::bytesWritten, [=](qint64 bytes){qDebug() << "bytesWritten";});
        QObject::connect(reply, &QNetworkReply::channelBytesWritten, [=](int channel, qint64 bytes){qDebug() << "channelBytesWritten";});
        QObject::connect(reply, &QNetworkReply::channelReadyRead, [=](int channel){qDebug() << "channelReadyRead";});
        QObject::connect(reply, &QNetworkReply::readChannelFinished, [=](){qDebug() << "readChannelFinished";});
        QObject::connect(reply, &QNetworkReply::readyRead, [=](){qDebug() << "readyRead";});
     
        QObject::connect(reply, &QNetworkReply::destroyed, [=](QObject *obj = nullptr){qDebug() << "destroyed";});
        QObject::connect(reply, &QNetworkReply::objectNameChanged, [=](const QString &objectName){qDebug() << "objectNameChanged";});
     
     
        QTimer *timer = new QTimer();
        timer->setSingleShot(false);
     
        QObject::connect(timer, &QTimer::timeout, [=]()
        {
            qDebug() << "error: " << reply->error();
            qDebug() << "isRunning: " << reply->isRunning();
            qDebug() << "isFinished: " << reply->isFinished();
            qDebug() << "isOpen: " << reply->isOpen();
            qDebug() << "isReadable: " << reply->isReadable();
            qDebug() << "isWritable: " << reply->isWritable();
            qDebug() << "isWidgetType: " << reply->isWidgetType();
            qDebug() << "isWindowType: " << reply->isWindowType();
            qDebug() << "isTextModeEnabled: " << reply->isTextModeEnabled();
            qDebug() << "isTransactionStarted: " << reply->isTransactionStarted();
     
            qDebug() << "---------------------";
        });
     
        timer->start(1000);
     
        return a.exec();
    }
    

 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.