I am using Qt 4.1 and want to post to server from the threads. Is this possible?
Printable View
I am using Qt 4.1 and want to post to server from the threads. Is this possible?
yes:)
can you give more information about your task?;)
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
while a function info() of the same class, implements
Code:
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
Code:
QList <MyThread *> list; for(int i=0;i<noOfThreads;i++) { MyThread *t = new MyThread(noOfLogs); list.append(t); 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
Then the exe, works with a call to start().
Can you point where i am probably going wrong?
Thanks a lot in advance.
Can you show us run()? You may need to start an event loop in every thread.Quote:
Originally Posted by Shambhavi
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?