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. Message box makes program to exit
Forum Updated to NodeBB v4.3 + New Features

Message box makes program to exit

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 688 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.
  • D Offline
    D Offline
    Dy3zz
    wrote on 28 Nov 2021, 12:27 last edited by
    #1

    Hi. I am new to Qt and i am trying to make a login page. After checking if the credentials are ok I am redirectig the user to a new page or show a message box if they are wrong. The problem is that if i call a message box, after click on OK , the program crash.

    if(rezultat=="OK"){
            home* homeWidget=new home();
            homeWidget->show();
        }else if(rezultat=="NOT OK"){
            QMessageBox::information(this,"Error","Wrong credentials!");
        }
    

    Here i check the result. How can i just print the message box and after click Ok still have the main window so i can try another account?

    J 1 Reply Last reply 28 Nov 2021, 12:33
    0
    • D Dy3zz
      28 Nov 2021, 12:27

      Hi. I am new to Qt and i am trying to make a login page. After checking if the credentials are ok I am redirectig the user to a new page or show a message box if they are wrong. The problem is that if i call a message box, after click on OK , the program crash.

      if(rezultat=="OK"){
              home* homeWidget=new home();
              homeWidget->show();
          }else if(rezultat=="NOT OK"){
              QMessageBox::information(this,"Error","Wrong credentials!");
          }
      

      Here i check the result. How can i just print the message box and after click Ok still have the main window so i can try another account?

      J Online
      J Online
      JonB
      wrote on 28 Nov 2021, 12:33 last edited by JonB
      #2

      @Dy3zz said in Message box makes program to exit:

      if i call a message box, after click on OK , the program crash.

      Your title says program exits, this says it "crashes". I doubt it crashes.

      If your message box is the only widget/window visible --- you do not have the main window currently open --- and it gets closed, Qt will exit the application. Use QApplication::setQuitOnLastWindowClosed(bool quit) to alter this behaviour.

      D 2 Replies Last reply 28 Nov 2021, 13:01
      1
      • J JonB
        28 Nov 2021, 12:33

        @Dy3zz said in Message box makes program to exit:

        if i call a message box, after click on OK , the program crash.

        Your title says program exits, this says it "crashes". I doubt it crashes.

        If your message box is the only widget/window visible --- you do not have the main window currently open --- and it gets closed, Qt will exit the application. Use QApplication::setQuitOnLastWindowClosed(bool quit) to alter this behaviour.

        D Offline
        D Offline
        Dy3zz
        wrote on 28 Nov 2021, 13:01 last edited by
        #3

        @JonB Sorry for the confusion. The program exit with code 0. My bad. I don't understand why the message box don't show above the main window as i saw in a tutorial

        1 Reply Last reply
        0
        • J JonB
          28 Nov 2021, 12:33

          @Dy3zz said in Message box makes program to exit:

          if i call a message box, after click on OK , the program crash.

          Your title says program exits, this says it "crashes". I doubt it crashes.

          If your message box is the only widget/window visible --- you do not have the main window currently open --- and it gets closed, Qt will exit the application. Use QApplication::setQuitOnLastWindowClosed(bool quit) to alter this behaviour.

          D Offline
          D Offline
          Dy3zz
          wrote on 28 Nov 2021, 13:07 last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dy3zz
            wrote on 28 Nov 2021, 13:11 last edited by
            #5

            I used setQuitOnLastWindowClosed(false) but now, after clicked ok in message box, all the windows are closed and the program is running like a daemon . I dont understand why my mainwindow is closing when i call message box.

            J 1 Reply Last reply 28 Nov 2021, 13:13
            0
            • D Dy3zz
              28 Nov 2021, 13:11

              I used setQuitOnLastWindowClosed(false) but now, after clicked ok in message box, all the windows are closed and the program is running like a daemon . I dont understand why my mainwindow is closing when i call message box.

              J Online
              J Online
              JonB
              wrote on 28 Nov 2021, 13:13 last edited by JonB
              #6

              @Dy3zz
              If you don't show any windows it will no longer exit, but then of course it will continue running with no visible windows. So you need to address that, i.e. show a window presumably. The main window (or any other window) does not close when you open or close a message box.

              D 1 Reply Last reply 28 Nov 2021, 14:43
              1
              • J JonB
                28 Nov 2021, 13:13

                @Dy3zz
                If you don't show any windows it will no longer exit, but then of course it will continue running with no visible windows. So you need to address that, i.e. show a window presumably. The main window (or any other window) does not close when you open or close a message box.

                D Offline
                D Offline
                Dy3zz
                wrote on 28 Nov 2021, 14:43 last edited by
                #7

                @JonB The main window (or any other window) does not close when you open or close a message box.

                This is the problem: my main window is closing when the message box is called.

                void MainWindow::on_goToLogin_clicked()
                {
                    this->hide();
                        //connector to sv
                    this->loginData.insert("Action","1");
                    this->loginData.insert("Username",QJsonValue::fromVariant(ui->loginUSername->text()));
                    this->loginData.insert("Pass",QJsonValue::fromVariant(ui->loginPass->text()));
                
                    QJsonDocument doc(this->loginData);
                    QByteArray ba=doc.toJson();
                    QString aux(ba);
                    cout<<aux.toStdString();
                    connecter.send_Buffer((char*)aux.toStdString().c_str());
                
                    std::string response=connecter.receiveMessage();
                    QString qstr = QString::fromStdString(response);
                    QJsonDocument jsonResponse = QJsonDocument::fromJson(qstr.toUtf8());
                
                    QJsonObject jsonObject = jsonResponse.object();
                    std::string rezultat = jsonObject["response"].toString().toStdString();
                
                    /////
                    if(rezultat=="OK"){
                        home* homeWidget=new home();
                        homeWidget->show();
                    }else if(rezultat=="NOT OK"){
                
                        QMessageBox::information(this,"Error","Wrong credentials!");
                    }
                }
                

                This is the function in main window. I understand that the main window should not dissapear when else if is on, but mine does.

                J 1 Reply Last reply 28 Nov 2021, 15:24
                0
                • D Dy3zz
                  28 Nov 2021, 14:43

                  @JonB The main window (or any other window) does not close when you open or close a message box.

                  This is the problem: my main window is closing when the message box is called.

                  void MainWindow::on_goToLogin_clicked()
                  {
                      this->hide();
                          //connector to sv
                      this->loginData.insert("Action","1");
                      this->loginData.insert("Username",QJsonValue::fromVariant(ui->loginUSername->text()));
                      this->loginData.insert("Pass",QJsonValue::fromVariant(ui->loginPass->text()));
                  
                      QJsonDocument doc(this->loginData);
                      QByteArray ba=doc.toJson();
                      QString aux(ba);
                      cout<<aux.toStdString();
                      connecter.send_Buffer((char*)aux.toStdString().c_str());
                  
                      std::string response=connecter.receiveMessage();
                      QString qstr = QString::fromStdString(response);
                      QJsonDocument jsonResponse = QJsonDocument::fromJson(qstr.toUtf8());
                  
                      QJsonObject jsonObject = jsonResponse.object();
                      std::string rezultat = jsonObject["response"].toString().toStdString();
                  
                      /////
                      if(rezultat=="OK"){
                          home* homeWidget=new home();
                          homeWidget->show();
                      }else if(rezultat=="NOT OK"){
                  
                          QMessageBox::information(this,"Error","Wrong credentials!");
                      }
                  }
                  

                  This is the function in main window. I understand that the main window should not dissapear when else if is on, but mine does.

                  J Online
                  J Online
                  JonB
                  wrote on 28 Nov 2021, 15:24 last edited by
                  #8

                  @Dy3zz said in Message box makes program to exit:

                  I understand that the main window should not dissapear when else if is on, but mine does.

                  This is your first line:

                  this->hide();
                  

                  What do you think that does?

                  D 1 Reply Last reply 28 Nov 2021, 15:28
                  3
                  • J JonB
                    28 Nov 2021, 15:24

                    @Dy3zz said in Message box makes program to exit:

                    I understand that the main window should not dissapear when else if is on, but mine does.

                    This is your first line:

                    this->hide();
                    

                    What do you think that does?

                    D Offline
                    D Offline
                    Dy3zz
                    wrote on 28 Nov 2021, 15:28 last edited by
                    #9

                    @JonB oh fuck, that line was forgotten there :( I am so sorry for wasting your time for suck a dummy thing . Thanks a lot!

                    1 Reply Last reply
                    1

                    1/9

                    28 Nov 2021, 12:27

                    • Login

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