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. Set "socketTimeout" option to QSqlDatabase connection(PostgreSQL)
Forum Update on Monday, May 27th 2025

Set "socketTimeout" option to QSqlDatabase connection(PostgreSQL)

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 391 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.
  • T Offline
    T Offline
    thaiboydigital
    wrote on 15 Oct 2020, 16:29 last edited by
    #1

    Hello,

    According to PostgreSQL doc( https://jdbc.postgresql.org/documentation/head/connect.html ) there is an socketTimeout option, that I want to use. But seems like QT couldn't accept it correctly.

    db = QSqlDatabase::addDatabase(db_prm.db_type, db_prm.db_name);
    
            if (!db.isValid())
                return -1;
            }
    
            db.setDatabaseName( db_prm.db_name );
            db.setHostName( db_prm.db_host );
            db.setPort( db_prm.db_port );
            db.setUserName( db_prm.db_user );
            db.setPassword( db_prm.db_pass );
            db.setConnectOptions( db_prm.options );
            db.setConnectOptions("socketTimeout=10");
    

    It returns error :

    Failure to open TEST_DB database. Error: invalid connection option "socketTimeout"
    

    It needed because QSqlDatabase::isOpen() doesn't provide correct information about current DB connection status in the cases when for example network interface go down after successful connection. Any ideas ? thx!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 15 Oct 2020, 16:58 last edited by Christian Ehrlicher
      #2

      The Qt PostgreSQL driver does not use the PSQL jdbc driver but libpq: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2

      1/2

      15 Oct 2020, 16:29

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved