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

Wont show another window

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 5 Posters 1.1k Views 4 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.
  • E Offline
    E Offline
    Eternus
    wrote on last edited by Eternus
    #1
       if(db.open()) {
            QMessageBox::information(this,"QMYSQL", "Sucesfull");
            QString username = ui->lineEdit_username->text();
            QString password = ui->lineEdit_password->text();
    
    
    
            QSqlQuery query(QSqlDatabase::database("QTUSERS"));
            query.prepare(QString("SELECT * FROM Users_QT WHERE username = :username AND password"));
    
    
            query.bindValue(":username", username);
            query.bindValue(":username", password);
    
            if(!query.exec()){
                QMessageBox::information(this, "Failed", "Nepodarilo sa pripojit na query");
            } else {
                while(query.next()){
                    QString usernameFromDB = query.value(1).toString();
                    QString passwordFromDB = query.value(2).toString();
    
                    qDebug()<<(usernameFromDB == username)<<(passwordFromDB == password);
    
                    if (usernameFromDB == username && passwordFromDB == password)  {
                        QMessageBox::information(this, "Uspesne", "Pripojil si query");
                        qDebug()<<"ops!";
    
    
    
                        Dialog logiin;
                        logiin.setModal(true);
                        logiin.show();
                        logiin.exec();
    
    
                    } else {
                        QMessageBox::information (this, "Failed", "Nepodarilo sa pripojit!");
                    }
    
                    }
                }
            }   else {
            QMessageBox::information(this,"QMYSQL", "Database not found");
        }
    
    
    
        }
    

    if login my app nothing happend only "Succesfull" succes is connect db correct but i cant connect to username and password i think i mean this :

               while(query.next()){
                    QString usernameFromDB = query.value(1).toString();
                    QString passwordFromDB = query.value(2).toString();
    
                    qDebug()<<(usernameFromDB == username)<<(passwordFromDB == password);
    
                    if (usernameFromDB == username && passwordFromDB == password)  {
                        QMessageBox::information(this, "Uspesne", "Pripojil si query");
                        qDebug()<<"ops!";
    

    this is my database :

    Screenshot 2020-09-20 at 21.52.53.png

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

      So what do you get exactly? QSqlQuery::prepare() and bindValue() have a return value which should be checked. Also QSqlQuery:lastError() should be used.

      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
      1
      • E Eternus
           if(db.open()) {
                QMessageBox::information(this,"QMYSQL", "Sucesfull");
                QString username = ui->lineEdit_username->text();
                QString password = ui->lineEdit_password->text();
        
        
        
                QSqlQuery query(QSqlDatabase::database("QTUSERS"));
                query.prepare(QString("SELECT * FROM Users_QT WHERE username = :username AND password"));
        
        
                query.bindValue(":username", username);
                query.bindValue(":username", password);
        
                if(!query.exec()){
                    QMessageBox::information(this, "Failed", "Nepodarilo sa pripojit na query");
                } else {
                    while(query.next()){
                        QString usernameFromDB = query.value(1).toString();
                        QString passwordFromDB = query.value(2).toString();
        
                        qDebug()<<(usernameFromDB == username)<<(passwordFromDB == password);
        
                        if (usernameFromDB == username && passwordFromDB == password)  {
                            QMessageBox::information(this, "Uspesne", "Pripojil si query");
                            qDebug()<<"ops!";
        
        
        
                            Dialog logiin;
                            logiin.setModal(true);
                            logiin.show();
                            logiin.exec();
        
        
                        } else {
                            QMessageBox::information (this, "Failed", "Nepodarilo sa pripojit!");
                        }
        
                        }
                    }
                }   else {
                QMessageBox::information(this,"QMYSQL", "Database not found");
            }
        
        
        
            }
        

        if login my app nothing happend only "Succesfull" succes is connect db correct but i cant connect to username and password i think i mean this :

                   while(query.next()){
                        QString usernameFromDB = query.value(1).toString();
                        QString passwordFromDB = query.value(2).toString();
        
                        qDebug()<<(usernameFromDB == username)<<(passwordFromDB == password);
        
                        if (usernameFromDB == username && passwordFromDB == password)  {
                            QMessageBox::information(this, "Uspesne", "Pripojil si query");
                            qDebug()<<"ops!";
        

        this is my database :

        Screenshot 2020-09-20 at 21.52.53.png

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

        @Eternus said in Wont show another window:

        query.prepare(QString("SELECT * FROM Users_QT WHERE username = :username AND password"));

        Bad query. To the best of my knowledge, unless MySQL is strangely C-/Python-like.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You are missing a : before password and you are binding twice to username.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          JonBJ 1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            You are missing a : before password and you are binding twice to username.

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

            @SGaist said in Wont show another window:

            You are missing a : before password

            It is missing the whole = :password after password, I assume.

            E 1 Reply Last reply
            0
            • JonBJ JonB

              @SGaist said in Wont show another window:

              You are missing a : before password

              It is missing the whole = :password after password, I assume.

              E Offline
              E Offline
              Eternus
              wrote on last edited by Eternus
              #6

              @JonB @SGaist
              if i put this :

                      query.prepare(QString("SELECT * FROM Users_QT WHERE username = :username AND password :password"));
              
              

              its says me this : if(!query.exec()){
              QMessageBox::information(this, "Failed", "Nepodarilo sa pripojit na query");

              but i dont know why mysql server running...

              JonBJ 1 Reply Last reply
              0
              • E Eternus

                @JonB @SGaist
                if i put this :

                        query.prepare(QString("SELECT * FROM Users_QT WHERE username = :username AND password :password"));
                
                

                its says me this : if(!query.exec()){
                QMessageBox::information(this, "Failed", "Nepodarilo sa pripojit na query");

                but i dont know why mysql server running...

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

                @Eternus said in Wont show another window:

                AND password :password

                Your query is still wrong. If you do not know what to put here you are going to struggle with MySQL.

                E 1 Reply Last reply
                0
                • JonBJ JonB

                  @Eternus said in Wont show another window:

                  AND password :password

                  Your query is still wrong. If you do not know what to put here you are going to struggle with MySQL.

                  E Offline
                  E Offline
                  Eternus
                  wrote on last edited by Eternus
                  #8

                  @JonB query.prepare(QString("SELECT * FROM Users_QT WHERE username = :username AND password = :password"));

                  if i put this its like before nothing show me ... not even that : QMessageBox::information(this, "Failed", "Nepodarilo sa pripojit na query");

                  JonBJ 1 Reply Last reply
                  0
                  • E Eternus

                    @JonB query.prepare(QString("SELECT * FROM Users_QT WHERE username = :username AND password = :password"));

                    if i put this its like before nothing show me ... not even that : QMessageBox::information(this, "Failed", "Nepodarilo sa pripojit na query");

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

                    @Eternus said in Wont show another window:

                    not even that : QMessageBox::information(this, "Failed", "Nepodarilo sa pripojit na query");

                    That's because for the first time you actually have a legitimate query.

                    E 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Eternus said in Wont show another window:

                      not even that : QMessageBox::information(this, "Failed", "Nepodarilo sa pripojit na query");

                      That's because for the first time you actually have a legitimate query.

                      E Offline
                      E Offline
                      Eternus
                      wrote on last edited by
                      #10

                      @JonB what you mean ?
                      i just following the tutorial.. and in turorial its works...

                      JonBJ 2 Replies Last reply
                      0
                      • E Eternus

                        @JonB what you mean ?
                        i just following the tutorial.. and in turorial its works...

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

                        @Eternus
                        You couldn't have followed whatever tutorial, because first you wrote

                        AND password
                        

                        then you wrote

                        AND password :password
                        

                        and now you write

                        AND password = :password
                        

                        So how could the tutorial you are following have all 3 of these, when only the last one is a correct query? And you had at least your query.bindValue()s wrong, I don't know what else. Maybe you have not been correctly copying from the tutorial?

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Beside the good points of @JonB, does your database actually contain data ?

                          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
                          • E Eternus

                            @JonB what you mean ?
                            i just following the tutorial.. and in turorial its works...

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

                            @Eternus
                            Your code now does not error because it is syntactically correct. If it does not enter your output loop it is because there are simply no matching records for your SELECT statement. Either no rows have the username/password you are supplying, or as @SGaist says you simply have not put any rows into the table.

                            E 1 Reply Last reply
                            1
                            • JonBJ JonB

                              @Eternus
                              Your code now does not error because it is syntactically correct. If it does not enter your output loop it is because there are simply no matching records for your SELECT statement. Either no rows have the username/password you are supplying, or as @SGaist says you simply have not put any rows into the table.

                              E Offline
                              E Offline
                              Eternus
                              wrote on last edited by
                              #14

                              @JonB Solved thanks guyz

                              Pablo J. RoginaP 1 Reply Last reply
                              0
                              • E Eternus

                                @JonB Solved thanks guyz

                                Pablo J. RoginaP Offline
                                Pablo J. RoginaP Offline
                                Pablo J. Rogina
                                wrote on last edited by
                                #15

                                @Eternus said in Wont show another window:

                                Solved thanks guyz

                                Would you mind sharing what the solution was? For the benefit of other users of the forum...

                                Upvote the answer(s) that helped you solve the issue
                                Use "Topic Tools" button to mark your post as Solved
                                Add screenshots via postimage.org
                                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                                E 1 Reply Last reply
                                0
                                • Pablo J. RoginaP Pablo J. Rogina

                                  @Eternus said in Wont show another window:

                                  Solved thanks guyz

                                  Would you mind sharing what the solution was? For the benefit of other users of the forum...

                                  E Offline
                                  E Offline
                                  Eternus
                                  wrote on last edited by Eternus
                                  #16

                                  @Pablo-J-Rogina
                                  ```
                                  QSqlQuery query(QSqlDatabase::database("QTUSERS"));

                                  
                                  to 
                                  

                                  QSqlQuery query(QSqlDatabase::database("MyConnect"));

                                  and 
                                          ```
                                  query.prepare(QString("SELECT * FROM Users_QT WHERE username = :username AND password"));
                                  

                                  to
                                  ```
                                  query.prepare(QString("SELECT * FROM Users_QT WHERE username = :username AND password = : password"));

                                  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