当互联网因已连接的 SSL 套接字而断开连接时,我正在尝试获取信号。这是我得出的方式QSslSocket
:
struct CloudSSL::Socket : public QSslSocket
{
Q_OBJECT public:
void ConnectSlots ()
{
connect(this, SIGNAL(readyRead()), this, SLOT(ReceiveData()));
connect(this, SIGNAL(disconnected()), this, SLOT(Disconnected()));
// *** None of the above or below is invoking when internet disconnects ***
connect(this, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(Error(QAbstractSocket::SocketError)));
}
virtual ~Socket ()
{
QObject::disconnect();
QSslSocket::abort();
}
public slots:
void ReceiveData ()
{
LOG("Socket received data...");
}
void Disconnected ()
{
LOG("Socket got disconnected...");
}
void Error (QAbstractSocket::SocketError error)
{
LOG("Socket error ", error);
}
}
这是它的初始化方式:
m_pSSLSocket = new Socket;
m_pSSLSocket->setProtocol(QSsl::TlsV1_2);
m_pSSLSocket->setLocalCertificateChain(QSslCertificate::fromPath(":/Certificate.pem", QSsl::Pem));
m_pSSLSocket->setPrivateKey(QSslKey(privateKeyFile.readAll(), QSsl::Rsa));
m_pSSLSocket->setSocketOption(QAbstractSocket::LowDelayOption, true); // <---
m_pSSLSocket->setSocketOption(QAbstractSocket::KeepAliveOption, true); // <---
m_pSSLSocket->connectToHostEncrypted(SAARATHY_URL, SAARATHY_PORT);
m_pSSLSocket->ignoreSslErrors();
总的来说,一切都很好。但是,如果我在我的 Ubuntu PC 中禁用 wifi,那么我不会像预期的那样收到任何网络错误QAbstractSocket::SocketError
:
QAbstractSocket::NetworkError
-- 7 -- 网络出现错误(例如,网络电缆被意外拔出)。
在此 Qn 之前引用了以下帖子:
问题:当互联网断开连接时,Qt 独有的接收信号的方式是什么?