0
我无法将信号连接到一个槽下面的代码:QT连接插槽/信号不工作
#include "myserver.h"
MyServer::MyServer(QObject *parent) :
QTcpServer(parent)
{
}
void MyServer::StartServer()
{
if(listen(QHostAddress::Any, 45451))
{
qDebug() << "Server: started";
emit servComando("Server: started");
}
else
{
qDebug() << "Server: not started!";
emit servComando("Server: not started!");
}
}
void MyServer::incomingConnection(int handle)
{
emit servComando("server: incoming connection, make a client...");
// at the incoming connection, make a client
MyClient *client = new MyClient(this);
client->SetSocket(handle);
//clientes.append(client);
//clientes << client;
connect(client, SIGNAL(cliComando(const QString&)),this, SLOT(servProcesarComando(const QString&)));
// para probar
emit client->cliComando("prueba");
}
void MyServer::servProcesarComando(const QString& texto)
{
emit servComando(texto);
}
的emit client->cliComando("prueba");
作品,但真正的“发射”没有。 控制台不显示任何连接错误,并且QDebug文本显示一切正常。 原始代码http://www.bogotobogo.com/cplusplus/sockets_server_client_QT.php
向我们显示您的信号处理代码。 – arrowd
_The emit client-> cliComando(“prueba”);作品_你怎么知道这个?此外,您可以简单地将SIGNAL连接到SIGNAL:_connect(client,SIGNAL(cliComando(const QString&)),this,SIGNAL(servComando(const QString &))); _ – Xplatforms
也用作参数的_“prueba”_显然不是_const QString&_ it取决于使用的编译器和Qt开关使用_QStringLiteral(“prueba”)_并设置SIGNAL/SLOT参数为_const QString_,如果直接向函数体插入参数并且不确定QMeta进程中的实例化参数是否仍然可用且具有值 – Xplatforms