View Full Version : error in creating QThread and Pthread

29th July 2011, 05:11
hi, i like to implement client and server model in qt. i ve done that, and now am gonna use multiple client. so am following threads.. i ve learned qthreads and used but got run time error . couldn’t found that.. here’s the code. in header file i declared.like
QT Code:

class mythread:public QThreads,public Widget
void run();

and .cpp file i defined it as,

QT Code:

void mythread::run()
//my client code

mythread t;

but i got sum error like debugger crashed and sometime program is not running. kindly tell me what i need to change here in the code. as am new to qt, kindly help me as soon as possible.

becos of error in QThread i plan to use pthread. as i ve already experience in linux so implemented pthread but it shows some syntax error couldn’t found tat too..

QT Code:

void *mythread(void*);

but it shows invalid argument 3 in pthread. the same way i ve used it in linux, there works, here its not working.. kindly tell me how to use the pthread(tell me the syntax properly) and modify here to use…and also tell if i ve used pthread it may create any problem while executing. like in gcc i ve used -lpthread in run time like tat i need to add any library or it will work by default.. if we want to add any library kindly give me full explanation about pthread to use it in qt

29th July 2011, 05:51
You don't have to use threads to service multiple clients but you can if you wish. The documentation contains two examples of exactly the sort of thing you are wanting to do:
Fortune Server Example
Threaded Fortune Server

Ultimately, if you plan to use pthreads then there is no point in us fixing your Qt code and the pthreads question should be addressed to another forum.

30th July 2011, 10:30
hi thanks for your reply.. see am gonna use qthreads now, okay what i need to change here??? i need:

Qthread should work independently in the widget class itself and also widget class should work independently apart from qthread..
my problem is qobject cannot inherit more than once. so what i need to change in my code?? .. i ve verified example but i dint get proper solution so please help..

thanks in advance,

30th July 2011, 10:41

class mythread:public QThreads,public Widget

is not correct in "Qt terms"

Widgets live in one thread only, usually the main application thread.
You perform the operations in another thread and display it via a widget. This means you need to establish some communication between (a) widget(s) and (a) thread(s).

30th July 2011, 17:36
yes actually i like to import some object from widget class.. like ui->textedit->settext like that.. for that i must import from widget class.. ok what i need to change? i cant avoid multiple inheritance... any other suggestions??