У меня возникли проблемы с подключением сигнала к слоту в следующем коде:
#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 а>
Q_OBJECT
в определении классаMyServer
. - person Marek R   schedule 30.08.2017QTcpServer
. Здесь следует использовать композицию. - person Marek R   schedule 30.08.2017