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;
}
{
switch (socketError) {
break;
msg = tr("The host was not found. Please check the "
"host name and port settings.");
break;
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());
}
errorbox->setText(msg);
errorbox->show();
}
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::SocketError 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();
}
To copy to clipboard, switch view to plain text mode
But This code is my TcpClient clas. i close server socket and i wait error but not catch. Where I made a mistake?
Bookmarks