我試圖用C++/Qt實現一個tcp套接字服務器。 首先,clientConnection本地聲明確實有效。QTcpServer如何從客戶端套接字讀取數據
QTcpSocket * clientConnection = tcpServer-> nextPendingConnection();
然而,當我試圖宣佈與私人類與QTcpSocket插座中的頭文件,而不是將它聲明爲局部類,爲了使用QTcpSocket->在ReadReady()讀取,我得到了錯誤。這些問題怎麼會發生?
void Server::respondNewConnection()
{
clientConnection = tcpServer->nextPendingConnection();
connect(clientConnection, &QAbstractSocket::disconnected,
clientConnection, &QObject::deleteLater);
connect(clientConnection, SIGNAL(readyRead()), this, SLOT(ReadyRead()));
clientConnection->write("[server]Welcome to server...", 100);
qDebug() << "02[server]Welcome to server..."<<endl;
statusLabel->setText(tr("test!"));
}
void Server::ReadyRead(){
qDebug() << "04[server]Ready to Read..." << endl;
/*
char buffer[100];
const int buffer_size = 100;
tcpSocket->read(buffer, buffer_size);
qDebug() << "05[server]Message from client: " << buffer << endl;
*/
}
「我的錯誤」 - 有哪些誤區? –
@FrankOsterfeld他們顯示在不是很好的名字'enter image description here鏈接:o –