我发现这样做的方法是扩展QNetworkAccessManager
和设置协议createRequest
:
class NetworkAccessManager : public QNetworkAccessManager
{
Q_OBJECT
public:
explicit NetworkAccessManager(QObject *parent = 0);
protected:
virtual QNetworkReply * createRequest(Operation operation, const QNetworkRequest & request, QIODevice * outgoingData = 0) {
// I have no idea why request is const, but I need to change it
QNetworkRequest notConstRequest = request;
QSslConfiguration conf = notConstRequest.sslConfiguration();
conf.setProtocol(QSsl::TlsV1_0);
notConstRequest.setSslConfiguration(conf);
return QNetworkAccessManager::createRequest(operation, notConstRequest, outgoingData);
}
};
然后我可以在我的QWebpage
using中设置它setNetworkAccessManager
。