Message box makes program to exit
-
wrote on 28 Nov 2021, 12:27 last edited by
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?
-
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?
wrote on 28 Nov 2021, 12:33 last edited by 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.
-
@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.
-
@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.
wrote on 28 Nov 2021, 13:07 last edited byThis post is deleted! -
wrote on 28 Nov 2021, 13:11 last edited by
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.
-
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.
wrote on 28 Nov 2021, 13:13 last edited by 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. -
@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.wrote on 28 Nov 2021, 14:43 last edited by@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.
-
@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.
wrote on 28 Nov 2021, 15:24 last edited by@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?
-
@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?
1/9