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. QSqlError("1045", "QMYSQ") Cannot edit table with QSqlTableModel
Forum Updated to NodeBB v4.3 + New Features

QSqlError("1045", "QMYSQ") Cannot edit table with QSqlTableModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsqltablemodelqsqlerrorerror 1045mysqllinux desktop
9 Posts 3 Posters 1.0k 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.
  • S Offline
    S Offline
    Shellcpp73
    wrote on 28 May 2022, 14:58 last edited by VRonin
    #1

    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.

    J 1 Reply Last reply 28 May 2022, 16:13
    0
    • S Shellcpp73
      28 May 2022, 14:58

      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.

      J Offline
      J Offline
      JonB
      wrote on 28 May 2022, 16:13 last edited by JonB
      #2

      @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)?

      S 1 Reply Last reply 29 May 2022, 17:08
      1
      • J JonB
        28 May 2022, 16:13

        @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)?

        S Offline
        S Offline
        Shellcpp73
        wrote on 29 May 2022, 17:08 last edited by Shellcpp73
        #3

        @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() << "!!!!!!!!";
        }
        

        }

        J 1 Reply Last reply 29 May 2022, 17:15
        0
        • S Shellcpp73
          29 May 2022, 17:08

          @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() << "!!!!!!!!";
          }
          

          }

          J Offline
          J Offline
          JonB
          wrote on 29 May 2022, 17:15 last edited by JonB
          #4

          @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.db is a persistent QSqlDatabase db member 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 variable QSqlDatabase db = QSqlDatabase::database(); when you need it.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Shellcpp73
            wrote on 29 May 2022, 17:55 last edited by Shellcpp73
            #5

            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

            C 1 Reply Last reply 29 May 2022, 18:17
            0
            • S Shellcpp73
              29 May 2022, 17:55

              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

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 29 May 2022, 18:17 last edited by Christian Ehrlicher
              #6

              @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.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              S 1 Reply Last reply 29 May 2022, 18:21
              0
              • C Christian Ehrlicher
                29 May 2022, 18:17

                @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.

                S Offline
                S Offline
                Shellcpp73
                wrote on 29 May 2022, 18:21 last edited by Shellcpp73
                #7

                @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.

                J 1 Reply Last reply 29 May 2022, 18:38
                0
                • S Shellcpp73
                  29 May 2022, 18:21

                  @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.

                  J Offline
                  J Offline
                  JonB
                  wrote on 29 May 2022, 18:38 last edited by
                  #8

                  @Shellcpp73
                  I would check how (and who) phpmyadmin is doing it then.

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 29 May 2022, 19:31 last edited by
                    #9

                    It's or sure no problem of Qt or the QSqlTableModel - fix your access rights.

                    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
                    0

                    7/9

                    29 May 2022, 18:21

                    • Login

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