[Interest] Qt Events/Signals and Loops (while ... for..)

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Thu Aug 30 07:54:13 CEST 2012


> You just have to start an eventloop, instead of sticking in your endless
> loop. If you use the Qt eventloop, you'll have no problems working with
> signals and slots in a thread. You do that by calling exec() from your run()
> method. Instead of using an endless loop, you might want to use things like
> a 0 timer.

As others have stated, you probably don't need to start a separate
thread for handling messages over your TCP socket (provided you're not
doing some computationally heavy task while processing your msg's as
that would stall the GUI thread). The asynchronous nature of Qt
networking makes it easy for you to just listen for signals (from
QTCPSocket) and react to them in a slot (in your main thread).

If however, you _do_ need to have a separate thread, read this article
first on how to "do it right"! :)
http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/

HTH,
-mandeep

>
> André
>
>
> Happy Hacking.
>
> --
> Abhishek
> http://thezeroth.net
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>



More information about the Interest mailing list