PDA

View Full Version : MultiThreading in Qt



manivannan_1984
7th November 2006, 18:17
Hi All,


Any body help me to implement multi threading .. I am not able to find any examples..

I am working on Automated Futures Trading System, i have a functions which reads a data from a particular file and send to my GUI. Consider I have data in many files, all files need to read parallely and send to GUI same time.

Pls give me suggestions..


Regards,
Mani

jacek
7th November 2006, 18:19
See %QTDIR%/examples/threads.

manivannan_1984
7th November 2006, 18:59
In the examples for each thread a class has been derived..

But I need to run multiple threads at a time (more than 10) in a single class, hence I cant create class for each thread.. But I going to perform a single function which has one parameter inside those threads.. so i need to run that function paralelly..

Without creating instances for that class where I have my functions, Can I implement multi threading..?

jacek
7th November 2006, 19:30
In the examples for each thread a class has been derived..
What prohibits you creating several instances of such class?

Brandybuck
7th November 2006, 19:54
In the examples for each thread a class has been derived..
If you have multiple threads and they all use the same run() function, (otherwise known as the thread routine), then you only need to create one QThread derived class.

3dch
7th November 2006, 19:56
You could use the Posix threads library directly which is available for Unix, Linux and Win systems. Have a look at this tutorial:

http://www.llnl.gov/computing/tutorials/pthreads/

But if ever possible you should derive from QThread and create an instance for every thread you need - for sure makes your life much easier.
Ernst

manivannan_1984
7th November 2006, 20:11
Thanks for all your suggestions..

Actually I have a requirement to do this with out creating instances.. But i think that is only the easier way...

Thanks,
Mani

jacek
7th November 2006, 20:26
Actually I have a requirement to do this with out creating instances..
Excuse me, but what do you intend to use instead? If you want to do it the object-oriented way, you have to use instances (i.e. objects).