Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

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

    General and Desktop
    3
    7
    2040
    Loading More Posts
    • 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 Royal
      Kelvin Royal last edited by 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) ?

      kshegunov 1 Reply Last reply Reply Quote 0
      • V
        VRonin last edited by

        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 Royal 1 Reply Last reply Reply Quote 2
        • Kelvin Royal
          Kelvin Royal @VRonin last edited by Kelvin Royal

          @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 Reply Quote 0
          • kshegunov
            kshegunov Moderators @Kelvin Royal last edited by 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 ...

            Read and abide by the Qt Code of Conduct

            Kelvin Royal 1 Reply Last reply Reply Quote 2
            • Kelvin Royal
              Kelvin Royal @kshegunov last edited by

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

              kshegunov 1 Reply Last reply Reply Quote 0
              • kshegunov
                kshegunov Moderators @Kelvin Royal last edited by

                @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 Royal 1 Reply Last reply Reply Quote 2
                • Kelvin Royal
                  Kelvin Royal @kshegunov last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post