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. Can a QTcpSocket emit the disconnected signal without emitting an RemoteHostClosedError error?

Can a QTcpSocket emit the disconnected signal without emitting an RemoteHostClosedError error?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 2.8k 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.
  • Kelvin RoyalK Offline
    Kelvin RoyalK Offline
    Kelvin Royal
    wrote on last edited by Kelvin Royal
    #1

    My question is a very simple one. The title says it all. I have been thinking about this for some time now. From what i see when RemoteHostClosedError is emitted the socket is disconnected. Is it both ways? Can a socket disconnect without emitting any error at all? Do i have to handle both signals seperately (Disconnected then Error with RemoteHostClosedError) ?

    kshegunovK 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      yes, try calling QTcpSocket::disconnectFromHost()

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      Kelvin RoyalK 1 Reply Last reply
      2
      • VRoninV VRonin

        yes, try calling QTcpSocket::disconnectFromHost()

        Kelvin RoyalK Offline
        Kelvin RoyalK Offline
        Kelvin Royal
        wrote on last edited by Kelvin Royal
        #3

        @VRonin Thank you! I see calling disconnectFromHost doesnt trigger the RemoteHostClosedError. But is there any other use case where disconnected can be emitted without RemoteHostClosedError too? I am asking this because i want to know if i always have to handle both

        1 Reply Last reply
        0
        • Kelvin RoyalK Kelvin Royal

          My question is a very simple one. The title says it all. I have been thinking about this for some time now. From what i see when RemoteHostClosedError is emitted the socket is disconnected. Is it both ways? Can a socket disconnect without emitting any error at all? Do i have to handle both signals seperately (Disconnected then Error with RemoteHostClosedError) ?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @Kelvin-Royal said in Can a QTcpSocket emit the disconnected signal without emitting an RemoteHostClosedError error?:

          Can a socket disconnect without emitting any error at all?

          Surely. If you close the socket you'd get the disconnected() signal but this isn't really an error, is it?

          Do i have to handle both signals seperately (Disconnected then Error with RemoteHostClosedError) ?

          The answer to this really depends on the situation, but as a rule of thumb I'd say yes.

          PS.
          Oh, I see I'm late to the party ...

          Read and abide by the Qt Code of Conduct

          Kelvin RoyalK 1 Reply Last reply
          2
          • kshegunovK kshegunov

            @Kelvin-Royal said in Can a QTcpSocket emit the disconnected signal without emitting an RemoteHostClosedError error?:

            Can a socket disconnect without emitting any error at all?

            Surely. If you close the socket you'd get the disconnected() signal but this isn't really an error, is it?

            Do i have to handle both signals seperately (Disconnected then Error with RemoteHostClosedError) ?

            The answer to this really depends on the situation, but as a rule of thumb I'd say yes.

            PS.
            Oh, I see I'm late to the party ...

            Kelvin RoyalK Offline
            Kelvin RoyalK Offline
            Kelvin Royal
            wrote on last edited by
            #5

            @kshegunov alright i will handle both then just to be on the safe side. so without calling disconnectFromHost, a socket cannot in anyway gracefully close itself without triggering the RemoteHostClosedError right? Is my assumption correct?

            kshegunovK 1 Reply Last reply
            0
            • Kelvin RoyalK Kelvin Royal

              @kshegunov alright i will handle both then just to be on the safe side. so without calling disconnectFromHost, a socket cannot in anyway gracefully close itself without triggering the RemoteHostClosedError right? Is my assumption correct?

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @Kelvin-Royal said in Can a QTcpSocket emit the disconnected signal without emitting an RemoteHostClosedError error?:

              so without calling disconnectFromHost, a socket cannot in anyway gracefully close itself without triggering the RemoteHostClosedError right? Is my assumption correct?

              I'd say yes, however disconnectFromHost might be called implicitly by Qt itself, e.g. if you delete the socket object directly.

              Read and abide by the Qt Code of Conduct

              Kelvin RoyalK 1 Reply Last reply
              2
              • kshegunovK kshegunov

                @Kelvin-Royal said in Can a QTcpSocket emit the disconnected signal without emitting an RemoteHostClosedError error?:

                so without calling disconnectFromHost, a socket cannot in anyway gracefully close itself without triggering the RemoteHostClosedError right? Is my assumption correct?

                I'd say yes, however disconnectFromHost might be called implicitly by Qt itself, e.g. if you delete the socket object directly.

                Kelvin RoyalK Offline
                Kelvin RoyalK Offline
                Kelvin Royal
                wrote on last edited by
                #7

                @kshegunov Alright. Now am ok! I understand QTcpSocket better. Thank you guys

                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