How to connect to the database correctly in QtWebApp
-
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);
-
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.
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.