PDA

View Full Version : class and event create



electronicboy
1st November 2009, 21:51
Hi all,

I have a socket class. I want to catch SocketError.

1. Method;
I send QWidget parameter from my class.

2. Method;
I create event and i catch this event from main function.

How can u recommend? And How can I catch this SocketError this socket class and I show my form?

squidge
1st November 2009, 22:12
3. connect error signal from socket to an appropriate slot in your code.

electronicboy
1st November 2009, 23:07
Thanks for recommend but I don't catch. I connected to SocketErrors signal and my slot is displayError.



TcpClient::TcpClient(const QString serverAddress,int serverPort)
{
_serverAddress = serverAddress;
_serverPort = serverPort;
tcpSocket = new QTcpSocket();
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(displayError(QAbstractSocket::SocketError)));
}
void TcpClient::displayError(QAbstractSocket::SocketErr or socketError)
{
QString msg;
switch (socketError) {
case QAbstractSocket::RemoteHostClosedError:
break;
case QAbstractSocket::HostNotFoundError:
msg = tr("The host was not found. Please check the "
"host name and port settings.");
break;
case QAbstractSocket::ConnectionRefusedError:
msg = tr("The connection was refused by the peer. "
"Make sure the fortune server is running, "
"and check that the host name and port "
"settings are correct.");
break;
default:
msg = tr("The following error occurred: %1.")
.arg(tcpSocket->errorString());
}
QMessageBox *errorbox = new QMessageBox();
errorbox->setText(msg);
errorbox->show();
}


But This code is my TcpClient clas. i close server socket and i wait error but not catch. Where I made a mistake?