Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Proper socket handling for iOS tablets
QtWS25 Last Chance

Proper socket handling for iOS tablets

Scheduled Pinned Locked Moved Solved Mobile and Embedded
ios
8 Posts 2 Posters 2.1k 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.
  • D Offline
    D Offline
    DRoscoe
    wrote on last edited by
    #1

    I have an iOS application written with Qt. The main application uses a QThread for socket communications with several connected signals to/from the main application thread. Realizing that under some circumstances the OS may take my connection away, such as when the table sleeps or my app is forced to the background, what is the best or proper way to:

    • deal with the application state change with respect to my connection
    • restore the connection when the application returns to the foreground

    Do I need to disconnect my signals reflexively when the application state changes to SUSPENDED and then reconnect them when the state changes back to the foreground?

    Can I just leave everything alone and check the connection state when I next try to send a message, and reconnect if connection is lost?

    I appreciate any insight.

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

      Hi,

      Do you need to handle that use case or rather have your application run in background to continue its work ?

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

      D 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Do you need to handle that use case or rather have your application run in background to continue its work ?

        D Offline
        D Offline
        DRoscoe
        wrote on last edited by
        #3

        @SGaist I'm going to stay away from background operation for the time being. I literally just want to be able to "freeze" when we are switched out, for whatever reason, and resume when we regain foreground context

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

          You should then connect the applicationStateChanged signal and store the state of your application when you get Qt::ApplicationSuspended. Depending on what your application is doing you might want to abort the current operation and restart it when the application resumes.

          If you can do it cleanly you shouldn't need to disconnect any signals.

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

          D 1 Reply Last reply
          0
          • SGaistS SGaist

            You should then connect the applicationStateChanged signal and store the state of your application when you get Qt::ApplicationSuspended. Depending on what your application is doing you might want to abort the current operation and restart it when the application resumes.

            If you can do it cleanly you shouldn't need to disconnect any signals.

            D Offline
            D Offline
            DRoscoe
            wrote on last edited by
            #5

            @SGaist what about the socket connection? I won't receive a socket disconnect signal. Should I proactively close it, or just leave it be and check for connection when it switches back to primary focus?

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

              I'd be proactive. That way you always know the state you were in and that might avoid useless bandwidth usage.

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

              D 1 Reply Last reply
              1
              • D Offline
                D Offline
                DRoscoe
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • SGaistS SGaist

                  I'd be proactive. That way you always know the state you were in and that might avoid useless bandwidth usage.

                  D Offline
                  D Offline
                  DRoscoe
                  wrote on last edited by
                  #8

                  @SGaist Thank you!

                  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