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. use to undeclared identifier on SQL Connecting
Forum Updated to NodeBB v4.3 + New Features

use to undeclared identifier on SQL Connecting

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 1.1k 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.
  • E Offline
    E Offline
    ELEMENTICY
    wrote on last edited by
    #1

    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
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      E 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

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

        E Offline
        E Offline
        ELEMENTICY
        wrote on last edited by
        #3

        @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
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          E 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            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.

            E Offline
            E Offline
            ELEMENTICY
            wrote on last edited by
            #5

            @Christian-Ehrlicher ok

            1 Reply Last reply
            0
            • E Offline
              E Offline
              ELEMENTICY
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • E Offline
                E Offline
                ELEMENTICY
                wrote on last edited by
                #7

                please help :)

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  • Login

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