QSqlDatabase: How to close socket connection after network is unplug



  • 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.



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



  • 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.



  • @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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.