View Full Version : Are QHttp n QHttpRequestHeader thread safe?

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

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

21st January 2006, 02: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();

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

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

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);
QObject::connect(t, SIGNAL(finished()),t, SLOT(deleteLater()));

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.

21st January 2006, 08: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.

21st January 2006, 08: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?