Solved Message box makes program to exit
-
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?
-
@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.
-
@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
-
This post is deleted! -
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.
-
@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. -
@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.
-
@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?
-
@JonB oh fuck, that line was forgotten there :( I am so sorry for wasting your time for suck a dummy thing . Thanks a lot!