PDA

View Full Version : sending soap request using QNetworkAccessManager question



babymonsta
15th April 2010, 07:28
I recently had to edit my program to send my soap message that is already in a qdomdocument, so I used QNetworkAccess Manager to send it, but is there anyway to actually send it without using signals and slots? Because for QNetworkAccessManager, the connect method uses signal and slots, is there a way to go around it and actually send the soap request without using signal and slot?

Here's a fragment of my code



connect(&manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply *)) );

QNetworkAccessManager manager;
QString data = document.toString();

QNetworkRequest networkReq;
networkReq.setHeader(QNetworkRequest::ContentTypeH eader, QLatin1String("text/xml;charset=utf-8"));
networkReq.setRawHeader("SOAPAction", "myurl");
networkReq.setUrl(url);

QNetworkReply *r = manager.post(networkReq, data.toAscii());


Currently this is what Im doing, but I would prefer to NOT use signal and slots, before this there was QHttp but unfortunately it has been removed and replaced with QNetworkAccessManager, so can anyone advice me how I could change my codes to not use signal and slots?

Thanks

wysota
15th April 2010, 10:34
What do you mean by "without signals and slots"? QHttp was not removed, by the way, it's just obsolete. How did you use QHttp "without signals and slots"?

_Stefan
15th April 2010, 10:44
In short, you can't!
I have had some trouble with QNetworkAccessManager before.

It has nice functionality, but if you want anything specific, it does not let you ;)
My problem was, that you cannot receive data in parts, which i needed (so when you do a http request and flush data every now and then, it will not trigger anything).

wysota
15th April 2010, 11:09
In short, you can't!
Oh, really? Are you sure? :)


My problem was, that you cannot receive data in parts, which i needed (so when you do a http request and flush data every now and then, it will not trigger anything).
Hmm... How did you try to read the data? Upon the readyRead() signal?

babymonsta
16th April 2010, 07:37
Such as sending the request and recieving it without the use of SIGNAL and SLOT.

For instance just using a code to set the host and then send the domdoc as a SOAP request to the server. I dont want to use SIGNAL and SLOT as Im creating a dll which will be given to my clients and they may not have Qt installed..

wysota
16th April 2010, 10:56
So.... why are you posting this in a Qt forum if you don't want to use Qt?

babymonsta
20th April 2010, 03:15
Please do not misunderstand, I am using Qt but I just do not wish to use the SIGNAL and SLOT, hence I'm asking whether there is a way to send my domdocument as a SOAP request without using SIGNAL and SLOT

Archimedes
20th April 2010, 05:00
Please do not misunderstand, I am using Qt but I just do not wish to use the SIGNAL and SLOT, hence I'm asking whether there is a way to send my domdocument as a SOAP request without using SIGNAL and SLOT

There's a logical bug in the above sentence, you are using Qt for your projects and you don't want signal/slots because the client may not have Qt installed?

There may probably be a way to do it without signal/slots, I guess you need to write some functions using the event mechanism of Qt.

Anyway, bellow it's not an answer to your question but just pointing out an alternative to QNetworkAccessManager, you may want to check this QtSOAP (http://qt.nokia.com/products/appdev/add-on-products/catalog/4/Utilities/qtsoap).

wysota
20th April 2010, 12:11
QtSoap uses QHttp internally and operates on signals and slots as well. In its current form it doesn't let you send more than one message at once as well, so it's kind of a limitation. I modified it some time ago to use QNetworkAccessManager as the transport layer but it requires Qt and signals and slots :)

babymonsta
21st April 2010, 03:48
Currently Im still using the signal and slot method from QNetworkAccessManager connect() method but is there really no way to just get the QNetworkReply without using the signal and slot? Because I tried to just use the manager to post the data and I didnt use the connect() method, my networkreply came back empty, so Im thinking maybe because the reply was retrieved at the wrong time (hence why signal and slot is very good at this part - to be able to get the response when a signal is emitted), but in short there really is no method to not have to use signal and slots?

wysota
21st April 2010, 08:55
But what is wrong with signals and slots? You can make your code pseudo-synchronous with QEventLoop if asynchronous call is a problem.