[Qt-interest] sockets and threads on linux

Jason H scorp1us at yahoo.com
Tue Feb 15 15:27:16 CET 2011


Um, no.
When you've created the QThread subclass, and passed the constructor the int 
descriptor and store it in a member variable, you've not yet started a thread, 
but instead created a QThread object. Then in your run() implementation, which 
is the actual thread, then you create a socket using the member variable int 
descriptor. No need to use moveToThread().


HTH


________________________________
From: pmqt71 <pmqt71 at gmail.com>
To: "william.crocker at analog.com" <william.crocker at analog.com>; 
qt-interest at trolltech.com
Sent: Tue, February 15, 2011 7:49:37 AM
Subject: Re: [Qt-interest] sockets and threads on linux


 
Upgrading Qt to 4.7 solved the problem. 
 
The target server was using Qt 4.5.0 shipped on Ubuntu repositories. Just as 
information, the problem is only with Qt 4.5.0 64 bit, not with Qt 4.5.0 32.
 
thanks to all.
pm
 
 
p.s. Bill, as I experienced, your steps 2 and 3 make the socket live in the main 
thread rather than in the one you create. I used moveToThread to correctly move 
the QTcpSocket object to the dedicated thread. See my previous messages where 
Thiago gave me the right suggestions.

 
 

 
2011/2/15 william.crocker at analog.com <william.crocker at analog.com>

Some detail omitted   :-)
>
>1 - Subclass QTcpServer and redefine incomingConnection(int)
>    ( The QTcpServer runs in the main thread. )
>
>2 - In this function, create a thread and pass it the int file descriptor.
>
>3 - In the ::run method of the thread, create a ::run/local QTcpSocket and
>    setSocketDescriptor with the incoming file desc.
>
>4 - Create some other ::run/local object to handle the readyRead()
>
>5 - Create and ::exec an event loop.
>
>I have a server which has been running flawlessly
>under this scenario for years.
>
>Bill
>
>
>> On Monday, 14 de February de 2011 19:43:34 Francisco Gonzalez wrote:
>>> In your implementation details both signal readyRead() and slot
>>> onReadyRead()  are members of your MyTcpSocket class, so when you move the
>>> pSocket object to the QThread th, you are moving both the signal, and the
>>> processing function. I do not understand how can it improve the socket
>>> capability of processing, as both functions live in the same thread.
>>
>
>_______________________________________________
>Qt-interest mailing list
>Qt-interest at qt.nokia.com
>http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110215/c379b969/attachment.html 


More information about the Qt-interest-old mailing list