Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Slot not called on specific location of connect() call
QtWS25 Last Chance

Slot not called on specific location of connect() call

Scheduled Pinned Locked Moved Unsolved General and Desktop
connect slotlocationpositionplace
5 Posts 2 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qtacc32
    wrote on 24 Dec 2015, 22:11 last edited by qtacc32
    #1

    Hi,

    Does anyone know why the second slot is never called? When I connect to the server, I only get the SIG 1 but not SIG 2.
    But where's the difference? Right after the first connect, the constructor of Connection leaves and execution continues right after the new, calling the second connect...

    Same with stateChanged signal. Connected in the constructor I get 1-2-3-0. Connected after new I get only 0.

    It's strange anyway, why does the connect signal even fire, especially after setSocketDescriptor? 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!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 25 Dec 2015, 11:47 last edited by
      #2

      @qtacc32
      Hello,

          connect(&connection.socket, &QSslSocket::connected, []{ LOG("SRV SOCK CONNECTED SIG 2"); });
      

      Your socket is 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.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qtacc32
        wrote on 25 Dec 2015, 17:35 last edited by
        #3

        Hi,

        It's just a simple example, actually Server is a friend of Connection and there is a std::map with a std::shared_ptr containing the Connection ;-)

        Also while I don't get a connected signal at all by the incomingConnection::connect call, I do get a stateChanged signal, but only with state 0 on disconnect..
        (I'll update the code on this)

        Thank you!

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qtacc32
          wrote on 2 Jan 2016, 03:18 last edited by
          #4

          I'm pushing this.

          It's strange, isn't it?

          K 1 Reply Last reply 2 Jan 2016, 13:06
          0
          • Q qtacc32
            2 Jan 2016, 03:18

            I'm pushing this.

            It's strange, isn't it?

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 2 Jan 2016, 13:06 last edited by
            #5

            @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.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved