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
Forum Updated to NodeBB v4.3 + New Features

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

    I'm trying to login with levels but the levels are not working. Someone can help me?
    I'm working with Qt 5.10.1 on Windows 10I'm trying to login with levels but the levels are not working. Someone can help me?
    I'm working with Qt 5.10.1 on Windows 10
    http://prntscr.com/jxy71z
    http://prntscr.com/jxy7pp

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

    @123456789
    What is your problem and what does this have to do with Qt?

    This is purely a question about your SQL query. Did you bother to examine QSqlQuery::lastError() when your query returned failure? (Hint: if you put an incomplete start-of-comment into a query string without an end-of-comment marker, what do you expect from SQL?)

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

      @JonB
      I hope sqlite will confirm that level 1 exists with this password and username.
      how to use QSqlQuery :: lastError ()?

      JonBJ 1 Reply Last reply
      0
      • 1 123456789

        @JonB
        I hope sqlite will confirm that level 1 exists with this password and username.
        how to use QSqlQuery :: lastError ()?

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

        @123456789
        I don't know what "level 1 exists" might mean.
        Look at the docs to how to use it (it just returns a string).

        P.S.
        While you are rewriting your query, you must not inject a raw string directly into a SQL statement without doing whatever to ensure it is correctly quoted. Especially with a password --- try having the password include a literal ' character, and see what happens.... One way would be to use the prepare() & bindValue() methods.

        P.P.S.
        Rather than always giving us your code via a screenshot link --- which we have to click on, and we cannot copy out of --- please change over to pasting the code as text, which really should be quicker anyway. In your post, insert a line with ``` (3-backticks) at the start, then your code, then a line with same 3 backticks at the end.

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

          @JonB
          I made it
          [6_1529661500932_main.cpp](Uploading 100%) [5_1529661500932_login.ui](Uploading 100%) [4_1529661500932_login.h](Uploading 100%) [3_1529661500931_login.cpp](Uploading 100%) [2_1529661500931_ex3.pro.user](Uploading 100%) [1_1529661500930_ex3.pro](Uploading 100%) [0_1529661500930_este.sqlite](Uploading 100%)
          https://we.tl/SuQp1qR8IM

          jsulmJ 1 Reply Last reply
          0
          • 1 123456789

            @JonB
            I made it
            [6_1529661500932_main.cpp](Uploading 100%) [5_1529661500932_login.ui](Uploading 100%) [4_1529661500932_login.h](Uploading 100%) [3_1529661500931_login.cpp](Uploading 100%) [2_1529661500931_ex3.pro.user](Uploading 100%) [1_1529661500930_ex3.pro](Uploading 100%) [0_1529661500930_este.sqlite](Uploading 100%)
            https://we.tl/SuQp1qR8IM

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @123456789 You made what? We cannot see anything except
            "[6_1529661500932_main.cpp](Uploading 100%) [5_1529661500932_login.ui](Uploading 100%) [4_1529661500932_login.h](Uploading 100%) [3_1529661500931_login.cpp](Uploading 100%) [2_1529661500931_ex3.pro.user](Uploading 100%) [1_1529661500930_ex3.pro](Uploading 100%) [0_1529661500930_este.sqlite](Uploading 100%)"

            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
              #7

              @jsulm
              i have not permissions
              i use wi transfer

              JonBJ 1 Reply Last reply
              0
              • 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 Offline
                    jsulmJ Offline
                    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 Offline
                            jsulmJ Offline
                            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 Offline
                                  jsulmJ Offline
                                  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