QSqlError("1045", "QMYSQ") Cannot edit table with QSqlTableModel
- 
But I have password to this user and in mysql console I can login but to here when i try to change data in DB with QSqlTablemodel QSqlError("1045", "QMYSQL: Невозможно соединиться", "Access denied for user 'myuser'@'localhost' (using password: NO)")entity.connectToDb(); if(entity.db.open()) { // entity.querymodel->setQuery("SELECT * FROM telcom"); // ui->tableView->setModel(entity.querymodel); entity.model = new QSqlTableModel(this,entity.db); entity.model->setEditStrategy(QSqlTableModel::OnManualSubmit); entity.model->setTable("telcom"); entity.model->select(); this->ui->tableView->setModel(entity.model); }I have password for 'myuser'@'localhost'. QSqldriver always tries to connect with password NO but if set a password NO in mysql for 'myuser'@'localhost' I have other error message "query does not exixst" so i think that's impossible to connect to phpmyadmin DB with no password. My local user have all needed privileges. 
- 
But I have password to this user and in mysql console I can login but to here when i try to change data in DB with QSqlTablemodel QSqlError("1045", "QMYSQL: Невозможно соединиться", "Access denied for user 'myuser'@'localhost' (using password: NO)")entity.connectToDb(); if(entity.db.open()) { // entity.querymodel->setQuery("SELECT * FROM telcom"); // ui->tableView->setModel(entity.querymodel); entity.model = new QSqlTableModel(this,entity.db); entity.model->setEditStrategy(QSqlTableModel::OnManualSubmit); entity.model->setTable("telcom"); entity.model->select(); this->ui->tableView->setModel(entity.model); }I have password for 'myuser'@'localhost'. QSqldriver always tries to connect with password NO but if set a password NO in mysql for 'myuser'@'localhost' I have other error message "query does not exixst" so i think that's impossible to connect to phpmyadmin DB with no password. My local user have all needed privileges. @Shellcpp73 
 Hello and welcome.You show nothing about how you connect to the database, which is where you specify a username and a password. It does not sound as though you are setting any password. That happens before you send it a query, and just before you open it. Where is your QSqlDatabase instance code, prior to calling QSqlDatabase::open(), or maybe you call bool QSqlDatabase::open(const QString &user, const QString &password)? 
- 
@Shellcpp73 
 Hello and welcome.You show nothing about how you connect to the database, which is where you specify a username and a password. It does not sound as though you are setting any password. That happens before you send it a query, and just before you open it. Where is your QSqlDatabase instance code, prior to calling QSqlDatabase::open(), or maybe you call bool QSqlDatabase::open(const QString &user, const QString &password)? @JonB I have fuction in Entiry class 
 void Entity::connectToDb()
 {while(!db.open()) { db.setHostName("localhost"); db.setUserName("username"); db.setPassword("qwerty123"); db.setDatabaseName("Main"); qDebug() << "!!!!!!!!"; }} 
- 
@JonB I have fuction in Entiry class 
 void Entity::connectToDb()
 {while(!db.open()) { db.setHostName("localhost"); db.setUserName("username"); db.setPassword("qwerty123"); db.setDatabaseName("Main"); qDebug() << "!!!!!!!!"; }} @Shellcpp73 
 qDebug() << db.lastError()?And what you have is odd. I do not know whether it even goes into the while()body. Can't you do normal:db.setHostName("localhost"); db.setUserName("username"); db.setPassword("qwerty123"); db.setDatabaseName("Main"); if (!db.open()) { qDebug() << db.lastError(); }Further it looks like your db/entity.dbis a persistentQSqlDatabase dbmember variable. This may not be related to your error, but Qt asks you not to do this. See https://doc.qt.io/qt-5/qsqldatabase.html#details and use local variableQSqlDatabase db = QSqlDatabase::database();when you need it.
- 
I'm ok with oping to data base and my query works well BUT my QSqlTablemodel don't save changes in the data base and I have error "Access denied for user 'myuser'@'localhost' (using password: NO)") with QSqlTablemodel 
- 
I'm ok with oping to data base and my query works well BUT my QSqlTablemodel don't save changes in the data base and I have error "Access denied for user 'myuser'@'localhost' (using password: NO)") with QSqlTablemodel @Shellcpp73 said in QSqlError("1045", "QMYSQ") Cannot edit table with QSqlTableModel: "Access denied for user 'myuser'@'localhost' Then fix your access rights for the user in the database or use another db-login which has write rights. 
- 
@Shellcpp73 said in QSqlError("1045", "QMYSQ") Cannot edit table with QSqlTableModel: "Access denied for user 'myuser'@'localhost' Then fix your access rights for the user in the database or use another db-login which has write rights. @Christian-Ehrlicher ohhhh I tried many times "myuser" has all needed rights and i have tried with root user and also i have same mistake , I can login to phpmyadmin with there users and make changes but not form QSqlTableModel ((( I don't know why QSQL driver always trying to connect with password NO. 
- 
@Christian-Ehrlicher ohhhh I tried many times "myuser" has all needed rights and i have tried with root user and also i have same mistake , I can login to phpmyadmin with there users and make changes but not form QSqlTableModel ((( I don't know why QSQL driver always trying to connect with password NO. @Shellcpp73 
 I would check how (and who)phpmyadminis doing it then.
- 
It's or sure no problem of Qt or the QSqlTableModel - fix your access rights. 
 

