[SOLVED] How to prevent form from closing after clicking OK from msgbox
-
wrote on 27 Jun 2014, 07:44 last edited by
Hi,
I have a form with a few line edit fields and one of them is mandatory. Upon clicking the Apply button, it will check if the mandatory field is filled in. If it's empty it will pop up a MsgBox like below:
!http://i59.tinypic.com/kb2cmr.png(http://i59.tinypic.com/kb2cmr.png)!
The thing is, I want the form to stay after Ok is clicked. Right now, the form disappears together with the msgbox when Ok is clicked. How do I prevent that to let user continue to stay on the form?
-
Please post the code of the slot that is called after you press "Apply".
-
wrote on 30 Jun 2014, 01:31 last edited by
Hi, my code is as below:
@
void rw::on_pushButton_clicked()
{rinsert = new Radio; rinsert->SerialNumber = ui->lineEdit->text(); if (formevent == "New") //assigned outside this function { if(rinsert->SerialNumber.isEmpty()) { QMessageBox alert; alert.setWindowTitle("Error"); alert.setText("Serial Number field is mandatory and must contain valid values"); alert.exec(); }else { //do something else } } //emit signal QString signal = "radio"; emit radiosignal(signal); this->close();
}
@ -
What is the close call ? It is closing your window. Hope it is according to your logic.
this->close();
-
As Dheerendra said, you are explicitly calling close(), so it is not surprising the window is closed.
Also, I suggest renaming the "signal" QString: this word is a macro defined by Qt, it might cause troubles.
1/5