QTcpServer监听不到newConnection

dreamersf 2012-07-26 12:44:25
//构造函数, 类继承与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()))
...全文
575 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lilimiao 2014-01-17
  • 打赏
  • 举报
回复
楼主 最后问题怎么解决的啊?
fishion 2012-07-27
  • 打赏
  • 举报
回复
是不是你在多线程中用错了this指针了
hdg3707 2012-07-26
  • 打赏
  • 举报
回复
头文件里声明:
private slots:
void getNewConnection();
cpp文件里:
void 类名::getNewConnection()
{
}
你可能没有头文件里加上slots这个关键字
dreamersf 2012-07-26
  • 打赏
  • 举报
回复
肯定加了,我又检查了一下,有的。
编译没有问题,运行的时候如果用了那个this指针,会有
QObject: Cannot create children for a parent that is in a different thread.
(Parent is CServerCommand(0x3efd28), parent's thread is QThread(0x7dafd0), curre
nt thread is QThread(0xfddb68)
的提示,但是如果this->m_temptcpServer = new QTcpServer;就不会有这个提示,但是不管哪种情况,getNewConnection()函数都是进不去的,是不是工程有什么需要设置的呀?我用的是vs2008
[Quote=引用 1 楼 的回复:]
头文件里声明:
private slots:
void getNewConnection();
cpp文件里:
void 类名::getNewConnection()
{
}
你可能没有头文件里加上slots这个关键字
[/Quote]

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧