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. Login
QtWS25 Last Chance

Login

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
17 Posts 3 Posters 2.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.
  • 1 123456789

    @jsulm
    i have not permissions
    i use wi transfer

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #8

    @123456789
    Permissions? To copy & paste code extracts into the text of your posts like I suggested?

    1 Reply Last reply
    0
    • 1 Offline
      1 Offline
      123456789
      wrote on last edited by
      #9

      LOGIN.CPP

      #include "login.h"
      #include "ui_login.h"

      #define Path_to_DB "C:/Users/kss/Documents/ex3/este.sqlite"

      login::login(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::login)
      {
      ui->setupUi(this);

      myDb = QSqlDatabase::addDatabase("QSQLITE");
      myDb.setDatabaseName(Path_to_DB);
      QFileInfo checkFile(Path_to_DB);
      
      if (checkFile.isFile())
      {
          if(myDb.open())
          {
               ui->lblresult->setText("entrou");
          }
      
      }else{
          ui->lblresult->setText("not");
      }
      

      }

      login::~login()
      {
      delete ui;
      qDebug() <<"connect closed";
      myDb.close();
      }

      void login::on_pushButton_2_clicked()
      {
      ui->txtpass->setText("");
      ui->txtuser->setText("");
      }

      void login::on_pushButton_clicked()
      {
      QString Username, Password;
      Username = ui->txtuser->text();
      Password = ui->txtpass->text();
      QString Rol1 = ui->cmbniveis->currentText();

      QSqlQuery qry;
      if(qry.exec("SELECT User, Password, Role FROM Users Where User=\'" + Username +
                  "\' AND Password=\'" + Password + "\' /*AND Role=\'" + Rol1 + "\'" ))
      {
          if(qry.next())
          {
              ui->lblresult->setText("Connectado");
              QString msg = "Username = " + qry.value(0).toString() + "\n" +
                            "Password = " + qry.value(1).toString();
                            "Role = " + qry.value(2).toString();
      
              QMessageBox::warning(this, "Bem sucedido", msg);
          }else{
      
        ui->lblresult->setText("errado");
          }
      
      
      }
      

      }

      jsulmJ 1 Reply Last reply
      0
      • 1 123456789

        LOGIN.CPP

        #include "login.h"
        #include "ui_login.h"

        #define Path_to_DB "C:/Users/kss/Documents/ex3/este.sqlite"

        login::login(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::login)
        {
        ui->setupUi(this);

        myDb = QSqlDatabase::addDatabase("QSQLITE");
        myDb.setDatabaseName(Path_to_DB);
        QFileInfo checkFile(Path_to_DB);
        
        if (checkFile.isFile())
        {
            if(myDb.open())
            {
                 ui->lblresult->setText("entrou");
            }
        
        }else{
            ui->lblresult->setText("not");
        }
        

        }

        login::~login()
        {
        delete ui;
        qDebug() <<"connect closed";
        myDb.close();
        }

        void login::on_pushButton_2_clicked()
        {
        ui->txtpass->setText("");
        ui->txtuser->setText("");
        }

        void login::on_pushButton_clicked()
        {
        QString Username, Password;
        Username = ui->txtuser->text();
        Password = ui->txtpass->text();
        QString Rol1 = ui->cmbniveis->currentText();

        QSqlQuery qry;
        if(qry.exec("SELECT User, Password, Role FROM Users Where User=\'" + Username +
                    "\' AND Password=\'" + Password + "\' /*AND Role=\'" + Rol1 + "\'" ))
        {
            if(qry.next())
            {
                ui->lblresult->setText("Connectado");
                QString msg = "Username = " + qry.value(0).toString() + "\n" +
                              "Password = " + qry.value(1).toString();
                              "Role = " + qry.value(2).toString();
        
                QMessageBox::warning(this, "Bem sucedido", msg);
            }else{
        
          ui->lblresult->setText("errado");
            }
        
        
        }
        

        }

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #10

        @123456789 said in Login:

        /*AND

        What is this?
        Also use http://doc.qt.io/qt-5/qsqlquery.html#lastError to see what the error was.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • 1 Offline
          1 Offline
          123456789
          wrote on last edited by
          #11

          @JonB
          help me please

          JonBJ 1 Reply Last reply
          0
          • 1 123456789

            @JonB
            help me please

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #12

            @123456789
            Both I & @jsulm have indeed told you what you need to do/read up. In a forum like this you need to put some effort in yourself, nobody wants to keep writing your complete code for you, we have our own work to do too....

            1 Reply Last reply
            3
            • 1 Offline
              1 Offline
              123456789
              wrote on last edited by
              #13

              Where?
              Not result
              QSqlQuery qry;
              if(qry.exec("SELECT User, Password, Role FROM Users Where User='" + Username +
              "' Password='" + Password + "' /* Role='" + Rol1 + "'" ))
              {

              @jsulm
              @JonB

              jsulmJ JonBJ 2 Replies Last reply
              0
              • 1 123456789

                Where?
                Not result
                QSqlQuery qry;
                if(qry.exec("SELECT User, Password, Role FROM Users Where User='" + Username +
                "' Password='" + Password + "' /* Role='" + Rol1 + "'" ))
                {

                @jsulm
                @JonB

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #14

                @123456789 When qry.exec() fails I would assume...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • 1 Offline
                  1 Offline
                  123456789
                  wrote on last edited by
                  #15

                  what @jsulm

                  1 Reply Last reply
                  0
                  • 1 123456789

                    Where?
                    Not result
                    QSqlQuery qry;
                    if(qry.exec("SELECT User, Password, Role FROM Users Where User='" + Username +
                    "' Password='" + Password + "' /* Role='" + Rol1 + "'" ))
                    {

                    @jsulm
                    @JonB

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #16

                    @123456789

                    if (qry.exec(...)) {
                       ...
                    } else {
                      qDebug() << qry.lastError();
                    }
                    
                    jsulmJ 1 Reply Last reply
                    2
                    • JonBJ JonB

                      @123456789

                      if (qry.exec(...)) {
                         ...
                      } else {
                        qDebug() << qry.lastError();
                      }
                      
                      jsulmJ Online
                      jsulmJ Online
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #17

                      @JonB said in Login:

                      qDebug(qry.lastError());

                      qDebug() << qry.lastError();
                      

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      2

                      • Login

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