Erledigt: Qthread tcp verbindung
Verfasst: 12. November 2010 14:49
Ich bin gerade dabei für meinen Server die Connections in Threads zu stecken. Jetzt habe ich das Problem, dass er readyRead irgendwie nicht anspricht. Ich bekomme keine Fehlermeldung.
Hier die Konsolenausgabe:
Hat jemand eine Idee?
Code: Alles auswählen
#include "clientconnection.h"
#include <QtNetwork>
clientConnection::clientConnection(int socketDescriptor, QObject*)
{
this->tcpSocket = new QTcpSocket;
this->tcpSocket->setSocketDescriptor(socketDescriptor);
qDebug() << "Neue Verbindung von: "<<tcpSocket->peerAddress();
}
void clientConnection::run()
{
qDebug() << "Thread gestartet"<<" Socket: "<<this->tcpSocket->socketDescriptor();
connect(this->tcpSocket,SIGNAL(readyRead()),this,SLOT(readData()));
qDebug() << "readyRead connected";
}
void clientConnection::readData()
{
qDebug() << "Lese Daten";
QByteArray tcpSockBytes = this->tcpSocket->readAll();
if (this->data.size() == 0)
{
QDataStream ins(tcpSockBytes);
ins.setVersion(QDataStream::Qt_4_7);
quint64 size;
ins >> size;
this->blockSize = size;
qDebug() << "tsize" <<size;
}
this->data.append(tcpSockBytes);
int i = (int) this->blockSize + (quint64) sizeof(quint64);
if (data.size() < i)
{
return;
}
qDebug() << "incomming data";
this->data.clear();
this->tcpSocket->flush();
}
Code: Alles auswählen
Neue Verbindung von: QHostAddress( "127.0.0.1" )
Thread gestartet Socket: 11
readyRead connected