Dumbledore
10th November 2007, 02:40
You can only debug what you know is wrong. In this case, with my cursory knowledge of Qt, I know this code should work. (Well I know it doesn't but I don't know why.)
Problem description: I can start multiple apps and they can connect to one another, but as soon as a connection is terminated all of the apps segfault.
The problem is most assuredly within here:
void MSocketThread::run() {
MSocket mSocket;
if ( 0 != socketDescriptor ) {
if ( !mSocket.setSocketDescriptor(socketDescriptor) ) {
std::cerr << "Failed to set SocketDescriptor." << endl;
}
/* Output who joined the server */
QHostAddress ipaddress = mSocket.peerAddress();
QString ipString(tr("<font color=blue>%1 has joined.</font>").arg(ipaddress.toString()));
emit relayIncomingText(ipString);
}
connect(&mSocket, SIGNAL(connected()),
this, SIGNAL(connectionEstablished()));
connect(&mSocket, SIGNAL(inboundText(QString)),
this, SIGNAL(relayIncomingText(QString)));
connect(this, SIGNAL(sigSend(QString)),
&mSocket, SLOT(send(QString)));
connect(&mSocket, SIGNAL(error()),
this, SIGNAL(quit()));
connect(&mSocket, SIGNAL(disconnected()), this, SLOT(quit()));
if ( 0 == socketDescriptor ) {
mSocket.connectToHost(ip, port);
}
exec(); //Begin event loop.
}
Problem description: I can start multiple apps and they can connect to one another, but as soon as a connection is terminated all of the apps segfault.
The problem is most assuredly within here:
void MSocketThread::run() {
MSocket mSocket;
if ( 0 != socketDescriptor ) {
if ( !mSocket.setSocketDescriptor(socketDescriptor) ) {
std::cerr << "Failed to set SocketDescriptor." << endl;
}
/* Output who joined the server */
QHostAddress ipaddress = mSocket.peerAddress();
QString ipString(tr("<font color=blue>%1 has joined.</font>").arg(ipaddress.toString()));
emit relayIncomingText(ipString);
}
connect(&mSocket, SIGNAL(connected()),
this, SIGNAL(connectionEstablished()));
connect(&mSocket, SIGNAL(inboundText(QString)),
this, SIGNAL(relayIncomingText(QString)));
connect(this, SIGNAL(sigSend(QString)),
&mSocket, SLOT(send(QString)));
connect(&mSocket, SIGNAL(error()),
this, SIGNAL(quit()));
connect(&mSocket, SIGNAL(disconnected()), this, SLOT(quit()));
if ( 0 == socketDescriptor ) {
mSocket.connectToHost(ip, port);
}
exec(); //Begin event loop.
}