PDA

View Full Version : WebService



Binary01
26th February 2016, 18:25
Hii EveryOne

We have two prog :
1- Client that represents the interface (Created by : QtQuick/QML) for entering data
2- Serveur Web (Java/JEE) that should menage the database

Communication between Client(Qml, Qt/C++) and Serveur Web should be done by : Webservice : Rest

I'm beginner in Webservice, I don't know where to start.
How can I establish the communication?
Steps to follow?

Cheers,

ChriD
29th February 2016, 11:11
You can try something like this for the Client (Qt)
(Be Aware that following code is rudimental and is not tested)
Ist not really a howto but i think it will help you in your first steps


QNetworkAccessManager networkManager;
QNetworkRequest request;
QByteArray arr;
QString requestData = "";
QString requestUrl= "www.google.at";

arr.append(requestData);

request.setHeader(QNetworkRequest::ContentTypeHead er, QVariant( QString("text/xml;charset=UTF-8")));
request.setHeader(QNetworkRequest::ContentLengthHe ader, QVariant( qulonglong(arr.size()) ));
request.setAttribute(QNetworkRequest::CacheLoadCon trolAttribute, QVariant( int(QNetworkRequest::AlwaysNetwork) ));
request.setUrl(QUrl(requestUrl));

QObject::connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onRequestFinished(QNetworkReply*)));
QObject::connect(networkManager, SIGNAL(authenticationRequired(QNetworkReply*,QAuth enticator*)), this, SLOT(onAuthenticationRequired(QNetworkReply*, QAuthenticator*)));

networkReply = networkManager.post(request, arr);
QObject::connect(this, SIGNAL(sigCancelRequest()), networkReply, SLOT(abort()));