[Qt-interest] Subclassing QTcpSocket

Bo Thorsen bo at fioniasoftware.dk
Wed Apr 20 15:20:52 CEST 2011


Den 20-04-2011 15:16, Thiago Macieira skrev:
> On Wednesday, 20 de April de 2011 14:52:36 Sven Grunewaldt wrote:
>> while (hasPendingConnections())
>> {
>>          QTcpSocket *socket = nextPendingConnection();
>>          QTcpSocketEx *client = qobject_cast<QTcpSocketEx*>(socket);
>>
>>          qDebug()<<  socket<<  client;
>> }
>>
>> Sadly this does not seem to work. The output is always
>> QTcpSocket(0x22318e0) QObject(0x0)
>>
>> What am I doing wrong?
>
> You're never creating a QTcpSocketEx object. The object returned from
> nextPendingConnection is always a QTcpSocket.
>
> You must override the virtual method in QTcpServer and create your
> QTcpSocketEx there.

And you have to add the Q_OBJECT macro to your class definition for it 
to have the proper classname in the debug output.

Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk



More information about the Qt-interest-old mailing list