BP :
I had a discussion about QNAM/SOAP usage with wysota some time ago. I recommend to search the forum for this thread, may be you will find the discussion useful. Solution that I came up with is:
Create a class that supports event processing.
class webserviceThread
: public QThread.
{
...
private:
boost::scoped_ptr<QNetworkAccessManager> _http;
}
class webserviceThread : public QThread.
{
...
private:
boost::scoped_ptr<QNetworkAccessManager> _http;
}
To copy to clipboard, switch view to plain text mode
the main thing this class does is that it instantiates event processing.
void webserviceThread::run()
{
exec();
}
void webserviceThread::run()
{
exec();
}
To copy to clipboard, switch view to plain text mode
The way I am processing requests is that I am adding it to the queue declared in the webserviceThread and I am having timer firing every half-second to check the exitence of a new request.
webserviceThread
::webserviceThread(const QString
& host,
int port
) : QThread(),_timerid
(-1), _http
(new QNetworkAccessManager
()){
...
QObject::connect (_http.
get(),
SIGNAL (finished
(QNetworkReply
*)),
this,
SLOT(responseReceived
(QNetworkReply
*)));
...
_timerid = startTimer(_timerinterval);
}
webserviceThread::webserviceThread(const QString& host, int port) : QThread(),_timerid(-1), _http(new QNetworkAccessManager())
{
...
QObject::connect (_http.get(), SIGNAL (finished (QNetworkReply *)), this, SLOT(responseReceived(QNetworkReply*)));
...
_timerid = startTimer(_timerinterval);
}
To copy to clipboard, switch view to plain text mode
Now you can declare the instance of webserviceThread anywhere and use it for communicating with your web server. In my case I have this:
{
public:
datamanager() {
...
_dmcenter.start();
}
private:
webserviceThread _dmcenter;
}
class datamanager : public QDialog
{
public:
datamanager() {
...
_dmcenter.start();
}
private:
webserviceThread _dmcenter;
}
To copy to clipboard, switch view to plain text mode
Wysota recommended usage of main thread for event processing, but I found this to be easier in terms of encapsulation of all QNAM/webservice logic inside one class.
Bookmarks