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. QSqlDatabase: How to close socket connection after network is unplug
Forum Updated to NodeBB v4.3 + New Features

QSqlDatabase: How to close socket connection after network is unplug

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 934 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.
  • uralbashU Offline
    uralbashU Offline
    uralbash
    wrote on last edited by uralbash
    #1

    When I unplug Ethernet cable and then try to execute any QSqlQuery or call db.close(), db.commit(), etc.. These calls block the thread, until I plug cable back, it can be very long time. Also db.isOpen() everything is true. How do I force a break db connection if I know that the network connection was lost?

    I test it with FireBird.

    JonBJ 1 Reply Last reply
    0
    • uralbashU uralbash

      When I unplug Ethernet cable and then try to execute any QSqlQuery or call db.close(), db.commit(), etc.. These calls block the thread, until I plug cable back, it can be very long time. Also db.isOpen() everything is true. How do I force a break db connection if I know that the network connection was lost?

      I test it with FireBird.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @uralbash
      I don't think you can, TCP doesn't break connections when you unplug cables. You have to put timeouts in. AFAIK anyway.

      1 Reply Last reply
      0
      • uralbashU Offline
        uralbashU Offline
        uralbash
        wrote on last edited by uralbash
        #3

        I do not need a timeout. I already know that the connection is broken. The question is how do I break the connection in QSqlDatabase object? Because db.close() block the thread and query.exec() block thread too and not close TCP connection just freezed.

        JonBJ 1 Reply Last reply
        0
        • uralbashU uralbash

          I do not need a timeout. I already know that the connection is broken. The question is how do I break the connection in QSqlDatabase object? Because db.close() block the thread and query.exec() block thread too and not close TCP connection just freezed.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @uralbash
          You may know the connection is broken, but TCP does not. So far as I know, it works by trying stuff and abandoning after a timeout. I don't know if you can do anything to avert that behaviour.

          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