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. QTcpSocket cancel connectToHost
Forum Updated to NodeBB v4.3 + New Features

QTcpSocket cancel connectToHost

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.9k 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.
  • T Offline
    T Offline
    TT_NBE
    wrote on last edited by
    #1

    Hello,

    I have used a QTcpSocket in my application and the socket works.

    The only problem I still have that once the 'connectToHost' function is called, there is no way to cancel it, so the user has to wait untill a timeout occurs. I know from past experiences that setting a timeout too short can sometimes lead to problems (especially on mobile connections) so my approach has always been set a long timeout and give the user the ability to 'cancel' but with QTcpSocket I can't seem to get this done.

    I've tried abort(), close(), disconnectFromHost() but all three seem to have no effect when the socket is not connected.

    So anyone an idea as to how to cancel a pending connectToHost()

    Thanks in advance

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Looking at the Qt source, this will continue to wait until timer expires. Either you need to delete the instance of Socket or call abort. Abort should take care. I have not experimented this.

      Also how are you calling abort(...) method ? If your app is single thread, whole application may be paused here. Are you trying to abort from another thread ?

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

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TT_NBE
        wrote on last edited by
        #3

        I've tried you suggestion, and called abort, and this in effect aborts the pending connection.

        So my issue actually was: when calling abort on the not connected socket, it does not emit a signal. So I'll have to emit a signal myself to inform the UI that the socket is back in the 'disconnected state'

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Try with error(...) or stateChanged(...) or aboutToClose(...) or disconnected signals. Either one of them will emit. According to the code disconnected(..) signal should emit.

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

          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