Error in creating Qthreads and pthread
-
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
{
public:
void run();
}@and .cpp file i defined it as,
QT Code:
@void mythread::run()
{
//my client code
exec();
}mythread t;
t.start();
t.wait();@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);
pthread_create(&threadid;,0,(void*)&mythread;,0);@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
-
Hi,
your problem is multiple inheritance:
@
class mythread:public QThreads,public Widget
{};
@As I read your threda, if not Linux, which is your target platform here? Windows? if yes, pthread does not exist there. Using QTHread is the easiest way here, but not as base class for a widget.
Create an own thread class and a widget class and make the thread a member of the widget if they are tighly coupled. But the widget has to live in the main thread.
You can read more on QTHread in "peppes article":http://developer.qt.nokia.com/wiki/ThreadsEventsQObjects
-
[quote author="shakthi" date="1311907824"]
@class mythread:public QThreads,public Widget
{
public:
void run();
}@
[/quote]Apart from the typos, if that Widget is actually a QWidget subclass, you're doing two serious mistakes here:
you cannot inherit from QObject more than once
you can't use ANY GUI code* in other threads but the main thread
Please elaborate if you want more help.
*namely, code that uses server-side features (widgets, pixmaps, possibly fonts, etc.).
-
hi thanks for your reply.. see am gonna use qthreads now, okay what i need to change here??? with out do multiple inheritance i cant import the objects like pushbutton, labels from widget class.. see i have clearly defined, am gonna use thread for multiple client and server connection..... i need:
Qthread should work independently in the widget class itself and also widget class should work independently apart from qthread..
yes qobject cannot inherit more than once. so what i need to change in my code?? please helpthanks in advance,
shakthi -
Hi shakthi,
perhaps we should start a bit earlier, before you decide what to put to a thread.
What exactly do you want to achieve?
How should your app look like?
If you really nee threads, think carefully where to use them and in which way. Is it a widget that wants to get the data inside a thread? then the thread could be a member of the widget for example. -
hi,
actually i have implemented client-server application which will read only if we press read button in client side and server side but now i ve designed normal chat messenger so i used qthreads to implement which can read from server and also server should read from client independently.. so i used qthreads and also imported widget class which has subclass of qwidget . but while executing i got some unknown error like debugger crashed , couldn't find it.. code i ve already posted above. in mythread class just done multiple inheritence with base class of qthread and widget class and declared run function alone and in .cpp file created thread object and use start function to initiate run function where i have defined widget object function.. hope now everyone understand.. please help me to find out the error and just give me the suggestion to use qthread
thanks in advance,
shakthi