[Qt-interest] sockets and threads on linux

Thiago Macieira thiago at kde.org
Sun Feb 13 17:59:21 CET 2011


On Sunday, 13 de February de 2011 17:42:06 pmqt71 wrote:
> Hi all,
> Hi Qt people, I hope the best for Qt and you!
> 
> I have a tcp client server program working well on WinXP, but not on linux.
> 
> MyTcpServer inherits from QTcpServer. the incomingConnection method creates
> a new socket and moves it to a new thread. The socket is handled by
> MyTcpSocket that inherits from QTcpSocket and implements the slots to manage
> client's incoming data:

Why? Why do you insist in using threads for networking I/O after I told you 
last week that you don't need to?

Use the thread to do the actual processing of the data. Not for the 
networking.

> On linux (Ubuntu 9.04 64bit) the readyRead signal is not fired. The
> incomingConnection is completed with no error, the pSocket objects gets the
> event ThreadChange related to the moveToThread operation. Nothing else.
> How can I debug?
> Qt 4.6.2

First of all, upgrade.

Second, debug the moveToThread call and check if the socket notifiers and the 
socket engine got moved to the other thread. While debugging moveToThread, you 
should be able to identify any children that got moved along with it.

Alternatively, or in addition, you can also put some breakpoints or debugging 
information in the register and unregisterSocketNotifier functions in the event 
dispatcher classes (QEventDispatcherUNIX or QEventDispatcherGlib). You should 
see the socket notifier be registered for the main thread, unregistered, then 
re-registered in the other thread.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110213/d95f1e25/attachment.bin 


More information about the Qt-interest-old mailing list