Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved use to undeclared identifier on SQL Connecting

    General and Desktop
    2
    8
    376
    Loading More Posts
    • 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.
    • E
      ELEMENTICY last edited by

      Hi,i need help.
      I got error "use to undeclared identifier" on my code,and im stuck on it.Please help me,im new to QT.Thank You = )\

      Here is the code:

      #include "login.h"
      #include "ui_login.h"
      #include "dialog.h"
      #include <QSqlRecord>
      
      QSQLITE::DB db;
      
      Login::Login(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::Login)
      {
          ui->setupUi(this);
          db = QSqlDatabase::addDatabase("QSQLITE");
          db.setHostName("localhost");
          db.setDatabaseName("login_system");
          db.setUserName("root");
          db.setPassword("");
      
          if(db.open())
              ui->label_4->setText("Connected...");
          else
              ui->label_4->setText("Disconnected...");
      }
      
      Login::~Login()
      {
          delete ui;
      }
      
      void Login::on_pushButton_clicked()
      {
          QString username,password;
          username = ui->lineEdit_username->text();
          password = ui->lineEdit_2_password->text();
      
          if(!db.open())
          {
              qDebug()<<"Not Connected to DataBase";
              return;
      
          }
      
          QSqlQuery qry;
      
          if(qry.exec("select * from login where username ='"+ username +"' and password='"+password +"'"))
          {
          int count=0;
              if(qry.next())
              {
                  count++;
              }
      
              if(count==1){
                  ui->label_4->setText("Sucessfully logged in");
                  this->hide();
                  Dialog dialog;
                  dialog.setModal(true);
                  dialog.exec();
      
              }
              if(count>1)
                  ui->label_4->setText("Username doesn't seem valid,or the password is wrong.Please try again");
              if(count<1)
                  ui->label_4->setText("Username doesn't seem valid,or the password is wrong.Please try again");
      
      
          }
      }
      

      The error is appear on line 6: "QSQLITE::DB db;"

      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        @ELEMENTICY said in use to undeclared identifier on SQL Connecting:

        QSQLITE::DB db;

        So what should this be? Please read the documentation on how to open a db connection.

        Qt has to stay free or it will die.

        E 1 Reply Last reply Reply Quote 3
        • Christian Ehrlicher
          Christian Ehrlicher Lifetime Qt Champion last edited by

          @ELEMENTICY said in use to undeclared identifier on SQL Connecting:

          QSQLITE::DB db;

          So what should this be? Please read the documentation on how to open a db connection.

          Qt has to stay free or it will die.

          E 1 Reply Last reply Reply Quote 3
          • E
            ELEMENTICY @Christian Ehrlicher last edited by

            @Christian-Ehrlicher i dont know,i could't find the answer in the doc,im new at c++,please tell me answer.
            Appreciate it : )

            1 Reply Last reply Reply Quote 0
            • Christian Ehrlicher
              Christian Ehrlicher Lifetime Qt Champion last edited by

              So I would start with a c++ book instead. And I don't need to provide some code as it is written exactly in the documentation I gave you.

              Qt has to stay free or it will die.

              E 1 Reply Last reply Reply Quote 1
              • E
                ELEMENTICY @Christian Ehrlicher last edited by

                @Christian-Ehrlicher ok

                1 Reply Last reply Reply Quote 0
                • E
                  ELEMENTICY last edited by

                  @Christian-Ehrlicher Doing that is good,but.You didt tell me the answer ;/

                  1 Reply Last reply Reply Quote 0
                  • E
                    ELEMENTICY last edited by

                    please help :)

                    1 Reply Last reply Reply Quote 0
                    • Christian Ehrlicher
                      Christian Ehrlicher Lifetime Qt Champion last edited by

                      @ELEMENTICY said in use to undeclared identifier on SQL Connecting:

                      Doing that is good,but.You didt tell me the answer ;/

                      I gave the answer to you - my link has a code example which does exactly what you want. See in the details section!

                      Qt has to stay free or it will die.

                      1 Reply Last reply Reply Quote 3
                      • First post
                        Last post