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 696 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 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?

    JonBJ 1 Reply Last reply
    0
    • D Dy3zz

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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
      1
      • JonBJ JonB

        @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 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
        • JonBJ JonB

          @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 last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dy3zz
            wrote on 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.

            JonBJ 1 Reply Last reply
            0
            • D Dy3zz

              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.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on 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
              1
              • JonBJ JonB

                @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 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.

                JonBJ 1 Reply Last reply
                0
                • D Dy3zz

                  @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.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on 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
                  3
                  • JonBJ JonB

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

                    • Login

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