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

Set "socketTimeout" option to QSqlDatabase connection(PostgreSQL)

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 415 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.
  • thaiboydigitalT Offline
    thaiboydigitalT Offline
    thaiboydigital
    wrote on 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
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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

      • Login

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