PDA

View Full Version : Are QHttp n QHttpRequestHeader thread safe?



Shambhavi
20th January 2006, 13:02
I am using Qt 4.1 and want to post to server from the threads. Is this possible?

zlatko
20th January 2006, 14:05
yes:)
can you give more information about your task?;)

Shambhavi
21st January 2006, 03:27
Sure. Mt requirement here is to simulate an environment where 'n' end systems are simultaneuosly posting x requests each, to a server.

I have a class, Http, which implements sending x requests to the server as follows using the QHttp n QHttpRequestHeader.

The constructor of this class has

QHttp op=new QHttp();
op->setHost(192.168.0.89);

while a function info() of the same class, implements

QHttpRequestHeader header( "POST", "server.php" ) ;
header.setValue( "Host", "192.168.0.89" ) ;
header.setContentType( "application/x-www-form-urlencoded" ) ;
op->request(header,logData);

I tested this and it is working perfectly.Now in order to get n systems doing this simultaneously, I am using a class inherited from QThread. I have reimplemented run() to create a Http object and call info().

In the main(), i have

QList <MyThread *> list;
for(int i=0;i<noOfThreads;i++)
{
MyThread *t = new MyThread(noOfLogs);
list.append(t);
QObject::connect(t, SIGNAL(finished()),t, SLOT(deleteLater()));
t->start();
}

This does not work, not a single request is sent. However if i call run() instead of start(), it works. But i guess, i should not be calling run() as then each thread will be created one after the other i the loop, which beats simultaneous requirement.

I however tried

QObject::connect(t, SIGNAL(finished()),t, SLOT(CallRun()));
Then the exe, works with a call to start().

Can you point where i am probably going wrong?

Thanks a lot in advance.

dimitri
21st January 2006, 09:32
I have reimplemented run() to create a Http object and call info().
Can you show us run()? You may need to start an event loop (http://doc.trolltech.com/4.1/qthread.html#exec) in every thread.

zlatko
21st January 2006, 09:33
Hm maiby available some errors in declaring MyThread?Show your *.h file pls.
What will happen if you start only one thread without cycle? Have your run() is exceuting?