[gelöst] multithreaded TCP-Server core dump
Verfasst: 12. März 2008 07:53
Ich bin Anfänger im Bereich C++ und QT also verzeiht mir bitte dumme Fehler.
Ich übe mich gerade an einem multithreaded TCP-Server und habe ein Problem mit zwei Klassen. Eine ist abgeleitet von QTcpSever, darin ist die "incomingConnection()" Methode überscrieben.
Die zweite Klasse, C2SSession, ist abgeleitet von QThread die "run()" methode sieht so aus:
Wenn nun ich den Thread beende und im Deconstructor das Socket-Objekt lösche gibt es einen Core Dump.
ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 8052280. Receiver '' (of type 'QSslSocket') was created in thread 805fcd8", file kernel/qcoreapplication.cpp, line 269
Aborted (core dumped)
Kann mir jemand sagen wo mein Denkfehler ist?
Ich übe mich gerade an einem multithreaded TCP-Server und habe ein Problem mit zwei Klassen. Eine ist abgeleitet von QTcpSever, darin ist die "incomingConnection()" Methode überscrieben.
Code: Alles auswählen
void C2S::incomingConnection(int socketDescriptor) {
C2SSession *session = new C2SSession(socketDescriptor, this);
connect(session, SIGNAL(finished()), session, SLOT(deleteLater()), Qt::DirectConnection);
session->start();
}Code: Alles auswählen
void C2SSession::run() {
client = new QSslSocket();
client->setProtocol(QSsl::TlsV1);
if (!client->setSocketDescriptor(socketDescriptor)) {
emit error(client->error());
delete client;
return;
}
client->setLocalCertificate("./mycert.pem");
client->setPrivateKey("./mycert.pem");
client->ignoreSslErrors();
connect(client, SIGNAL(readyRead()), SLOT(readyRead()), Qt::DirectConnection);
connect(client, SIGNAL(disconnected()), SLOT(disconnected()), Qt::DirectConnection);
connect(client, SIGNAL(sslErrors(const QList<QSslError>&)), SLOT(sslErrors(const QList<QSslError>&)), Qt::DirectConnection);
connect(client, SIGNAL(encrypted()), SLOT(encrypted()), Qt::DirectConnection);
handler = new C2SXmlHandler(this);
connect(handler, SIGNAL(streamStart()), SLOT(streamStart()), Qt::DirectConnection);
connect(handler, SIGNAL(startTls()), SLOT(startTls()), Qt::DirectConnection);
reader = new QXmlSimpleReader();
source = new QXmlInputSource(client);
reader->setContentHandler(handler);
reader->setErrorHandler(handler);
reader->setFeature("http://xml.org/sax/features/namespace-prefixes", true);
reader->parse(source, true);
exec();
}ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 8052280. Receiver '' (of type 'QSslSocket') was created in thread 805fcd8", file kernel/qcoreapplication.cpp, line 269
Aborted (core dumped)
Kann mir jemand sagen wo mein Denkfehler ist?