Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QTcpServer won't call "incomingConnection" in Windows applications
Qt 6.12 LTS is out! See what's new in the release blog

[Solved] QTcpServer won't call "incomingConnection" in Windows applications

Scheduled Pinned Locked Moved General and Desktop
14 Posts 3 Posters 11.0k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #4

    Am I the only one to have that problem?

    For information, same code was working under Ubuntu using Qt 5.2.1

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #5

      what is happening at the client side ? You can use the following two signals

      1. error()
      2. connected()

      Connect these two slots at client side to some function. Error function should give what is the error if not able to connect.

      My suspect is that IP address passed from client is some how not correct.

      Do you have client and server on the same system ?
      Are you running client & servers running in different system ?

      If they are running different system, just check IP address of server you used to connect.

      If you are not able to verify with any of the above, then we can check the network packets with wireshark and see whatz is happening at network level. This is our last and final step. Hope we don't reach this.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #6

        Test is done using 127.0.0.1 on the same system.

        On client side it's pretty simple:
        if (! tcpSocket->waitForConnected() ){
        cerr << "could not find host" << endl;
        exit(1);
        }

        cout << "connect state " << tcpSocket->state();
        

        Connect state shows 3, which is state "Connected" I believe.

        So yes, client really seems to get connected, and as I stated before, the server signal "newConnection" is emitted when client is run...

        Really strange.... Just seems that the server mechanism to call "incomingConnection " is not working on my windows system... Any change has been done from 5.2.1 to 5.3.1??

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
          wrote on last edited by
          #7

          client really seems to get connected, and as I stated before, the server signal >“newConnection” is emitted when client is run

          What do you mean here ? newConnection signal is emitted at server when client is run ? Do you mean to say signal is not emitted when client is connecting but it emits later ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          https://www.pthinks.com

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #8

            Yes exactly, the server signal is emitted as soon as the client connects.

            But I used that signal just to check if server was seing the connection, as I intially just wanted to get the incomingConnection call mechanism to work, exactly as in the threaded fortune server Qt example.

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
              wrote on last edited by
              #9

              Since newConnection is happening it means that incomingConnection(..) is surely working. Internally base implementation calls incommingConnection(..) when ever the connection request arrives.

              Last thing I would like to see is the your class declaration where incomingConnection(...) is defined and it's corresponding implementation. You can paste the code here.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              https://www.pthinks.com

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #10

                oh dear oh dear...

                I think I got it....

                In the Qt example it's declared

                protected:
                void incomingConnection(int socketDescriptor);

                But actually it's a qintptr socketDescriptor ...

                So I guess it was recognised as a qintptr under my 32bit linux... But a different method when compiled on my windows 64 system...

                I can't test it right now but I'm pretty sure that's the issue...

                I'll tell you tomorrow :)

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  Hi,

                  Are you by any chance looking at a Qt 4.8 example while using Qt 5 ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #12

                    Yes seems I got trapped by the Qt version when looking at the example...

                    That was a nice trap to get into :p

                    Still didn't test with the new definition but pretty confident that was my issue :p

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      Which example was it ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #14

                        I first looked at the correct examples, but probably came back to the wrong one with a google search pointing to an old example version :(

                        Here was the old one declared as an "int".
                        http://qt-project.org/doc/qt-4.8/network-threadedfortuneserver.html

                        I recompiled this for 64 bit just changing int into qintptr and: now it works like a charm!!!

                        Thanks for the help, will be more carefull with the new qtype declarations :p

                        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
                        • Unsolved