端口QHttp类从Qt4到Qt5
我在Qt4中创建了一个使用QHttp类的应用程序。新的Qt 5在QNetworkAccessManager类中具有几乎相同的功能,但我需要一些调整:端口QHttp类从Qt4到Qt5,qt,qtnetwork,qnetworkrequest,Qt,Qtnetwork,Qnetworkrequest,我在Qt4中创建了一个使用QHttp类的应用程序。新的Qt 5在QNetworkAccessManager类中具有几乎相同的功能,但我需要一些调整: 我的代码是: http=new QHttp ( this ); if ( config->brokerurl.indexOf ( "https://" ) ==0 ) neworkAccess-> http->setHost ( lurl.host(),QHttp::ConnectionModeHttps,
http=new QHttp ( this );
if ( config->brokerurl.indexOf ( "https://" ) ==0 )
neworkAccess->
http->setHost ( lurl.host(),QHttp::ConnectionModeHttps,
lurl.port ( 443 ) );
else
http->setHost ( lurl.host(),QHttp::ConnectionModeHttp,
lurl.port ( 80 ) );
我找到了使用URL地址发布消息的QNetworkRequest类,但我使用的http和https在不同的端口中工作,因此我还需要设置此ConnectionMode(http或https)
有没有办法在QNetworkRequest中也设置ConnectionModehttp->post ( lurl.path(),req.toUtf8(),&httpSessionAnswer );
Qt 4中的该文件具有以下特征:
int post ( const QString & path, const QByteArray & data, QIODevice * to = 0 )<br><br>
发布消息(请求+数据)并同时获得答复(QIODevice*data
)的新Qt5等效功能是什么您可以在QUrl()中设置端口。类似(极度简化): 对于错误: 您可以在QNetworkReply中找到信号。 你可以做:
connect(&http,SIGNAL(finished(QNetworkReply *)),
this,SLOT(finishedSlt(QNetworkReply *)));
在您的插槽中:
finishedSlt(QNetworkReply *reply){
connect(reply,SIGNAL(sslErrors(const QList<QSslError> &)),
SLOT(sslErrorsSlt(QList<QSslError> &)));
}
finishedSlt(QNetworkReply*reply){
连接(应答、信号(sslErrors(常量QList&)),
插槽(SSLERROSSLT(QList&));
}
免责声明:此代码仅为示例,不打算复制/粘贴到生产系统中
connect(&http,SIGNAL(finished(QNetworkReply *)),
this,SLOT(finishedSlt(QNetworkReply *)));
finishedSlt(QNetworkReply *reply){
connect(reply,SIGNAL(sslErrors(const QList<QSslError> &)),
SLOT(sslErrorsSlt(QList<QSslError> &)));
}