[Qt-interest] Subclassing QTcpSocket
Sven Grunewaldt
strayer at olle-orks.org
Wed Apr 20 14:52:36 CEST 2011
Hi,
I want to attach some values to a QTcpSocket so I'm sublassing it like this:
class ClientData
{
public:
QByteArray clientDataBuffer;
HttpHeaders clientHeaders;
};
class QTcpSocketEx : public QTcpSocket
{
Q_OBJECT
public:
QTcpSocketEx(QObject *parent = 0) : QTcpSocket(parent) {}
ClientData clientData;
};
I use the new class in my subclassed QTcpServer like this:
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?
Regards,
Sven Grunewaldt
More information about the Qt-interest-old
mailing list