Problem with QThread..
-
Please use @ tags for code. I edited your post, but in further posts please use it by yourself.
I don't see any usage of your MyThread class. And it should be inherited from QThread if you want to use threading.
-
Usually (mis)using threads causes gui going unresponsive...
Qt already have event loop, using own events and/or signal/slot system.
http://doc.qt.nokia.com/latest/signalsandslots.html
http://doc.qt.nokia.com/latest/eventsandfilters.html -
-
@above,
I am actually coding for a messenger
and my client should always be in listen mode,it should be listening for messages from other clients.
But when the client i listening for messages,the client become crashes after some time.How could i handle this?
-
You can look at the examples: "here":http://doc.qt.nokia.com/4.7/network-network-chat.html
-
You have to subclass MyThread from QThread then define in its run method what you want to do in the background. Did you read the "basic thread example":http://doc.qt.nokia.com/4.7/qthread.html#details ?
-
Maybe in your case it's better to use the QThread::run() default implementation that runs a local (for thread) event loop.
You simply have to create your QWidget and your QThread, than use QObject::moveToThread() method and call the QThread::start() method.References:
http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/
http://doc.qt.nokia.com/4.7/qthread.html#start
http://doc.qt.nokia.com/4.7/qobject.html#moveToThread -
[quote]and my client should always be in listen mode,it should be listening for messages from other clients.[/quote]
Please read my article here: http://developer.qt.nokia.com/wiki/ThreadsEventsQObjects . This seems to be the another case where threads are absolutely not needed (and indeed they just make your life a lot harder).
-
[quote author="peppe" date="1292837082"]
Please read my article here: http://developer.qt.nokia.com/wiki/ThreadsEventsQObjects . This seems to be the another case where threads are absolutely not needed (and indeed they just make your life a lot harder).[/quote]Really good article :D
-
[quote author="Il Rugginoso" date="1292836477"] http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/[/quote] Thanks for the tipp! I didn't know the concepts behind the QThread class...
-
[quote author="Wolf P." date="1292842687"][quote author="Il Rugginoso" date="1292836477"] http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/[/quote] Thanks for the tipp! I didn't know the concepts behind the QThread class...
[/quote]You're welcome :D