qt Tcp连接不上
MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(start()));
}
void MainWindow::start()
{
TcpConnect *tcp = new TcpConnect();
tcp->start(); //调用类TcpConnect中的函数startServer
}
以下是类TcpConnect中函数(关于此类中的ui是通过MainWindow中的getui函数传递的)
void TcpConnect::startServer()
{
m_pTcpServer = new QTcpServer();
m_pTcpServer->listen(QHostAddress::Any,12000);
ui->pushButton_2->setEnabled(false); //点击后禁用pushButton
this->connect(m_pTcpServer,SIGNAL(newConnection()),this,SLOT(newConnect()));
}
void TcpConnect::newConnect()
{
pTcpSocketServer = m_pTcpServer->nextPendingConnection();
this->connect(pTcpSocketServer,SIGNAL(readyRead()),this,SLOT(readMessage()));
}
void TcpConnect::readMessage()
{
QByteArray rec = pTcpSocketServer->readAll(); //read data
QString ss = QVariant(rec).toString();
ui->textBrowser_2->append(ss);
}
这是服务端,但是无法接收到客户端的连接?????