I have an application created in Qt 4 that uses the QHttp class. The new Qt 5 has almost the same functionality in the QNetworkAccessManager class, but I need a couple of tweaks:
My piece of code is:
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 ) );
I have found the QNetworkRequest class that uses the URL address to post a message, but I'm using http and https that work in different ports, so I need to set also this ConnectionMode(http or https).
Is there a way to also set a ConnectionMode in QNetworkRequest?
I have this piece of code:
http->post ( lurl.path(),req.toUtf8(),&httpSessionAnswer );
This in Qt 4 has the signature:
int post ( const QString & path, const QByteArray & data, QIODevice * to = 0 )<br><br>
In Qt 5 we have:
QNetworkReply * post ( const QNetworkRequest & request, QIODevice * data ) QNetworkReply * post ( const QNetworkRequest & request, const QByteArray & data )
What is the new Qt 5 equivalent for posting a message (a request+data) and also getting an answer(
QIODevice * data
)?
You can set the port in QUrl(). Something like (extremely simplified):
For sslErrors:
You find the signal in QNetworkReply. You can do:
In your slot:
Disclaimer: This code is only an example and not meant to be copied/pasted into a production system.