void Dialog::acceptConnection() { tcpServerConnection = tcpServer.nextPendingConnection(); connect(tcpServerConnection, SIGNAL(readyRead()), this, SLOT(updateServerProgress())); connect(tcpServerConnection, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError))); serverStatusLabel->setText(tr("Accepted connection")); tcpServer.close(); }
// 接收连接 void Server::acceptConnection() { tcpServerConnection = tcpServer.nextPendingConnection(); connect(tcpServerConnection, SIGNAL(readyRead()), this, SLOT(updateServerProgress())); connect(tcpServerConnection, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError))); ui->serverStatusLabel->setText(tr("接受连接")); // 关闭服务器,不再进行监听 tcpServer.close(); }
void MainWindow::acceptConnection() //接受连接 { tcpServerConnection = tcpServer->nextPendingConnection(); tcpServerConnection->write("hello"); connect(tcpServerConnection,SIGNAL(readyRead()),this, SLOT(updateServerProgress())); connect(tcpServerConnection, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError))); //tcpServer-> ui->serverStatusLabel->setText(tr("accept connection")); tcpServer->close(); }