[Qt-interest] global thread not running until main app starts

Bradley T. Hughes bradley.hughes at nokia.com
Wed Jan 14 10:36:08 CET 2009


Paul England wrote:
[snip]
>    connect( socket, SIGNAL( readyRead() ), this, SLOT( socket_ready_read() ) );
[snip]
> void my_thread::socket_ready_read()
> {
>    printf( "Got something\n" );
>      while ( socket->canReadline() ) {
>       // parse line
>       // store value in 'data', which has global scope.
>    }
> }

Be aware that QObjects have affinity to a single thread, and that thread is 
the one that will execute the object's slots. By default, the object is 
affine to the instantiating thread. So, QApplication is affine to the main() 
thread, and your QTcpSocket is affine to your my_thread.

But what thread is your my_thread instance affine to (and where is your slot 
going to be executed)? Hint: it's not affine to itself...

-- 
Bradley T. Hughes (Nokia-D-Qt/Oslo), bradley.hughes at nokia.com
Sandakervn. 116, P.O. Box 4332 Nydalen, 0402 Oslo, Norway



More information about the Qt-interest-old mailing list