Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. read and save number from sqlite
Forum Updated to NodeBB v4.3 + New Features

read and save number from sqlite

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
6 Posts 3 Posters 1.3k Views 2 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
    MrLibya
    wrote on last edited by kshegunov
    #1

    I've made a login dialog and i want check if the id & pass that input in the dialog is right , and sae the id of the user

    so i've made class :

    class users
    {
    public:
        static int id;
    };
    

    and the functuin:

    void LoginDialog::on_OK_clicked()
    {
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("SalesManagement.db");
        QSqlQuery query("SELECT * FROM [main].[users]");
        users user;
        while (query.next())
        {
            if (query.value(1) == ui->username_input->text() &&
                   query.value(2) ==  ui->password_input->text())
            {
                user.id = query.value(0).toInt();
                break;
            }
        }
        ui->label_3->setText(QString::number(user.id));
    }
    

    but i get this error :

    alt textb12b81d0d27d99f5.png))

    kshegunovK 1 Reply Last reply
    0
    • M MrLibya

      I've made a login dialog and i want check if the id & pass that input in the dialog is right , and sae the id of the user

      so i've made class :

      class users
      {
      public:
          static int id;
      };
      

      and the functuin:

      void LoginDialog::on_OK_clicked()
      {
          QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
          db.setDatabaseName("SalesManagement.db");
          QSqlQuery query("SELECT * FROM [main].[users]");
          users user;
          while (query.next())
          {
              if (query.value(1) == ui->username_input->text() &&
                     query.value(2) ==  ui->password_input->text())
              {
                  user.id = query.value(0).toInt();
                  break;
              }
          }
          ui->label_3->setText(QString::number(user.id));
      }
      

      but i get this error :

      alt textb12b81d0d27d99f5.png))

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      Show us your users class and the definition of users::id. Usually you'd get this error if you haven't defined the static variable.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MrLibya
        wrote on last edited by
        #3

        read the topic again i've already include the users class in the topic

        kshegunovK 1 Reply Last reply
        0
        • M MrLibya

          read the topic again i've already include the users class in the topic

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @MrLibya
          Do you have a definition for this static member in your cpp? Something like this:

          int users::id = 0;
          
          // ... 
          void LoginDialog::on_OK_clicked()
          {
              // ...
          }
          

          Read and abide by the Qt Code of Conduct

          M 1 Reply Last reply
          1
          • kshegunovK kshegunov

            @MrLibya
            Do you have a definition for this static member in your cpp? Something like this:

            int users::id = 0;
            
            // ... 
            void LoginDialog::on_OK_clicked()
            {
                // ...
            }
            
            M Offline
            M Offline
            MrLibya
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              You're not opening your database and also not doing any checks to see whether your query ran successfully.

              Also, since you are only giving the name of the database file, it will be created in the same folder as the application unless you already provide that file.

              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