【问题标题】:Runtime error with QTcpSocket and slots and signalsQTcpSocket、插槽和信号的运行时错误
【发布时间】:2012-03-01 14:48:55
【问题描述】:

我正在编写一些代码来建立 TCP 套接字,但在尝试设置我尝试收听的信号时遇到错误。

代码是:

connection = new QTcpSocket(this);

connect(connection,SLOT(connected()),this,SIGNAL(onConnection()));
connect(connection,SLOT(readyRead()),this,SIGNAL(gotData()));
connect(connection,SLOT(disconnected()),this,SIGNAL(onConnection()));

我得到的错误是:

 Object::connect: Attempt to bind non-signal QTcpSocket::connected()
 Object::connect: Attempt to bind non-signal QTcpSocket::readyRead()
 Object::connect: Attempt to bind non-signal QTcpSocket::disconnected()

我找不到其他有同样问题的人。我在想这只是我正在做的愚蠢的事情。我在这个程序中的其他信号正在工作。

【问题讨论】:

  • 语法是connect(sender,receiver),反之则不然。先有信号,然后是槽(或其他信号)。

标签: qt signals-slots


【解决方案1】:

你使用 QObject::connect 方法不好!

你必须使用这样的连接方法:

connection = new QTcpSocket(this);

connect(connection,SIGNAL(connected()),this,SLOT(onConnection()));
connect(connection,SIGNAL(readyRead()),this,SLOT(gotData()));
connect(connection,SIGNAL(disconnected()),this,SLOT(onConnection()));

如需更多信息,请转至here

【讨论】:

  • QObject::connect 不是这个问题的原因
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-13
相关资源
最近更新 更多