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. [SOLVED] Need help in solving multiple clicking of dialog boxes
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Need help in solving multiple clicking of dialog boxes

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.1k Views 1 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.
  • S Offline
    S Offline
    sharon_obl82
    wrote on last edited by
    #1

    I have a login box where the checking is done in main.cpp. The values for user and password will be passed from login.cpp to main.cpp and then back to login.cpp. Message box will pop up upon clicking the button but I have to click at least 3-4 times before it goes away! Can someone help to debug on this?

    login.cpp:
    @

    void Login::on_login_clicked()
    {

    QString user = ui->username->text();
    QString passwd = ui->password->text();
    

    if ((!ui->username->text().isEmpty()) && (!ui->password->text().isEmpty()))
    {

        //call checking from main.cpp
        MainWindow mw;
        mw.checkLogin(user, passwd);
    
        if (mw.checkLogin(user, passwd) == 0)
        {
            qDebug() << "Success! Close dialog box";
            QDialog::close();
        }
    }
    else
     {
        qDebug() << "Invalid credential provided!";
     }
    

    }
    @

    main.cpp:
    @
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    MainWindow w;
    w.showMaximized();
    w.show();
    
    
    Login MyLogIn;
    

    //i seriously don't know what this is for but it needs to be there for the login form to open
    if (MyLogIn.exec() == QDialog::Accepted)
    {

    }
    

    return a.exec();

    }

    int MainWindow::checkLogin(QString a, QString b)
    {
    QMessageBox msgBox;
    QString aa = a;
    QString bb = b;

    if((aa=="admin") && (bb=="1234"))
    {
         qDebug() << "Login success!";
         msgBox.setText("Login success!"); //i have to click this like 3-4 times before it goes away!
         msgBox.exec&#40;&#41;;
         return 0;
    }
    else
    {
        qDebug(&#41; << "Login FAILED!";
        msgBox.setText("Login FAILED!"); //same with this
        msgBox.exec(&#41;;
    
        return 1;
    }
    

    }
    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      You call checkLogin twice so you have message box twice.
      @
      mw.checkLogin(user, passwd); // <-- First message box

      if (mw.checkLogin(user, passwd) == 0) // <-- Second
      @

      Also you create MainWindow twice.
      It is not a probem now, but later if the MainWindow will have some complicated logic it will be a big problem.

      And you don't need to show a window twice
      @
      w.showMaximized(); // <-- this line is enough
      w.show();
      @

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Hi,
        IMHO Please, please, please, first read a good C++ book. Then a good Qt book and then start programming.
        You posted code before because you didn't understand the dialog stuff, this is almost the same.

        Greetz, Jeroen

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sharon_obl82
          wrote on last edited by
          #4

          Thanks for the help, appreciate it.

          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