Ich habe eine Server geschrieben (abgeleitet von QTcpServer), der die Client-Anfragen in Threads verarbeitet. Hier mal die ueberschriebene incommingConnection-Funktion:
Code: Alles auswählen
void receiver::incomingConnection(int socketDescriptor)
{
CommunicatorCall *comm = new CommunicatorCall(...); //kein Parent!
connect( comm, SIGNAL(finished()),
comm, SLOT(deleteLater()), Qt::DirectConnection);
//die error- und event-Messages werden einfach weitergereicht:
connect( comm, SIGNAL(errorMessage(const QString&)),
SIGNAL(errorMessage(const QString&)), Qt::QueuedConnection);
connect( comm, SIGNAL(eventMessage(const QString&)),
SIGNAL(eventMessage(const QString&)), Qt::QueuedConnection);
comm->start();
}
Code: Alles auswählen
...
private:
QTimer *timeout;
...
Code: Alles auswählen
timeout = new QTimer;
timeout->setSingleShot(true);
timeout->setInterval(10 * 1000); //our timeout is 10 sec
...
connect( timeout, SIGNAL(timeout()),
this, SLOT(timeoutOccurred()), Qt::DirectConnection);
...
timeout->start();
timeoutOccurred(void):
Code: Alles auswählen
timeout->stop();
socket->disconnectFromHost();
disconnect( timeout, SIGNAL(timeout()),
this, SLOT(timeoutOccurred()));
connect( timeout, SIGNAL(timeout()),
this, SLOT(disconnected()), Qt::DirectConnection);
timeout->start();
Code: Alles auswählen
timeout->stop();
quit(); //exit thread
QObject::startTimer: QTimer can only be used with threads started with QThread
Allerdings taucht sie nur ab und zu auf und ist damit leider nicht reproduzierbar. Hat jemand eine Idee, an was das liegen koennte bzw. wie man an die Sache rangehen kann?
Ich bin fuer jeden Tipp dankbar!
Col