Slot not called on specific location of connect() call
-
Hi,
Does anyone know why the second slot is never called? When I connect to the server, I only get the
SIG 1but notSIG 2.
But where's the difference? Right after the firstconnect, the constructor ofConnectionleaves and execution continues right after thenew, calling the secondconnect...Same with
stateChangedsignal. Connected in the constructor I get 1-2-3-0. Connected afternewI get only 0.It's strange anyway, why does the
connectsignal even fire, especially aftersetSocketDescriptor? What triggers it?class Connection { QSslSocket socket; public: Connection(qintptr socketDescriptor); virtual ~Connection() {}; }; Connection::Connection(qintptr socketDescriptor) { socket.setSocketDescriptor(socketDescriptor); QObject::connect(&socket, &QSslSocket::connected, []{ LOG("SRV SOCK CONNECTED SIG 1"); }); // slot called QObject::connect(&socket, &QSslSocket::stateChanged, [](QAbstractSocket::SocketState socketState) { LOG("SRV SOCK STATECHANGED SIG 1: " << socketState); }); // slot called with socketState 1-2-3-0 } void Server::incomingConnection(qintptr socketDescriptor) { Connection& connection = *new Connection(socketDescriptor); connect(&connection.socket, &QSslSocket::connected, []{ LOG("SRV SOCK CONNECTED SIG 2"); }); // slot not called connect(&connection.socket, &QSslSocket::stateChanged, [](QAbstractSocket::SocketState socketState) { LOG("SRV SOCK STATECHANGED SIG 2: " << socketState); }); // slot called, but only with socketState 0 }Thank you and have some nice holidays!
-
@qtacc32
Hello,connect(&connection.socket, &QSslSocket::connected, []{ LOG("SRV SOCK CONNECTED SIG 2"); });Your
socketis private, I suspect that might be a problem. One other thing that caught my eye, I hope you realize that this:Connection& connection = *new Connection(socketDescriptor);is a memory leak.
Kind regards.
-
Hi,
It's just a simple example, actually Server is a
friendof Connection and there is a std::map with a std::shared_ptr containing the Connection ;-)Also while I don't get a
connectedsignal at all by the incomingConnection::connect call, I do get astateChangedsignal, but only with state 0 on disconnect..
(I'll update the code on this)Thank you!
-
@qtacc32
If you're still struggling with this if possible try sharing a real piece of the code. It might be something trivial that doesn't show up in the example (which looks fine). Or at least a MWE that reproduces the problem, since I could not run your example, since it's not complete.Kind regards.