我正在编写一些代码来建立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()));
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
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()
Run Code Online (Sandbox Code Playgroud)
我找不到其他有同样问题的人.我在想,我正在做的事情是愚蠢的.我在该计划中的其他信号正在发挥作用.
您使用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()));
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请访问此处.