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. How to connect to the database correctly in QtWebApp
Forum Updated to NodeBB v4.3 + New Features

How to connect to the database correctly in QtWebApp

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 5 Posters 2.6k 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.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #21

    Sanks, it is work

        dataBase = QSqlDatabase::addDatabase("QPSQL", "conectionName");
        dataBase.setDatabaseName("db_game_tamada");
        dataBase.setUserName("postgres");
        dataBase.setPassword("1qaz");
        //ResumeDB.setHostName("127.0.0.1");
        dataBase.setPort(5433);//*/
    

    and in query need set database

    QSqlQuery query(dataBase);
    
    1 Reply Last reply
    0
    • SGaistS SGaist

      As we already suggested several times: go read the documentation of addDatabase. You are not setting a connection name, therefore all your DataBase objects are using default connection.

      And as I already have written numerous times: Do not keep a local QSqlDatabase member variable. There's a warning in the documentation about that.

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #22

      Repeating myself:

      @SGaist said in How to connect to the database correctly in QtWebApp:

      You need to use a unique name for each connection.

      @SGaist said in How to connect to the database correctly in QtWebApp:

      And as I already have written numerous times: Do not keep a local QSqlDatabase member variable. There's a warning in the documentation about that.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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