QSslSocket 默认自动搜索代理设置,当系统中存在代理时,执行 connectToHostEncrypted 会导致 socket error: UnsupportedSocketOperationError,具体错误是 connect error is "The proxy type is invalid for this operation";
查找原因步骤:(执行以下代码,可以获取具体失败原因)
cpp
this->connectToHostEncrypted(qstrIP, port);
bool b = this->waitForEncrypted();
if (!b) {
qDebug() << "connect error is " << this->errorString();
}
解决办法:
cpp
先:this->setProxy(QNetworkProxy::NoProxy);
后:this->connectToHostEncrypted(qstrIP, port);