Use QSqlDatabase as the only active session



  • Hi guys,

    I'm a newbie in Qt and my situation is as follows: I'm developing a system with which I need to connect to a database, particularly PostgreSQL.
    I have a home screen that allows log in (connect to the database with a username and password). After the start of session to be successful, i need to interact with information in the database. Obviously, I want to have only one active session database.
    My question is, i can use QSqlDatabase to accomplish this? or i need to implement a singleton as best solution? If i can use the QSqlDatabase, how do you do to manage a single instance in the whole system?

    Best Regards.



  • No, you can use QSqlDatabase, and there is no need for a separate singleton implemenation to manage your database. QSqlDatabase already uses (named) connections that you can simply refer to.


Log in to reply
 

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