QTcpServer监听不到newConnection
//构造函数, 类继承与QWidget
.................
this->m_temptcpServer = new QTcpServer(this);
if (!m_temptcpServer->listen(QHostAddress::Any,5697))
{
QMessageBox::warning(this, "提示", "监听端口失败。", QMessageBox::Yes);
}
//在我用另外一个程序连接这个端口的时候,那个程序连接上了,但是我的slot函数从类不会被触发,不知道什么原因,愁死了
connect(this->m_temptcpServer, SIGNAL(newConnection()), this, SLOT(getNewConnection()))
[解决办法]
头文件里声明:
private slots:
void getNewConnection();
cpp文件里:
void 类名::getNewConnection()
{
}
你可能没有头文件里加上slots这个关键字