QDialog closed unexpectedly
-
Hi,
My platform: Linux kubuntu
QT version: 4.7.1I am trying to achieve the following:
I have a simple QDialog with 4 QLineEdits and 2 QPushButtons for submit and reject.
The 4 QLineEdits are connected to a slot as follows:connect(m_line_edit_1, SIGNAL(returnPressed()), this, SLOT(checkLineEdits()) connect(m_line_edit_2, SIGNAL(returnPressed()), this, SLOT(checkLineEdits()) connect(m_line_edit_3, SIGNAL(returnPressed()), this, SLOT(checkLineEdits()) connect(m_line_edit_4, SIGNAL(returnPressed()), this, SLOT(checkLineEdits())
where the slots performs the following:
void checkLineEdits() { bool disable_submit = m_line_edit_1->text().isEmpty() || m_line_edit_2->text().isEmpty() || m_line_edit_3->text().isEmpty() || m_line_edit_4->text().isEmpty(); m_submit_button->setEnabled(false == disable_submit); }
My problem is, after
exec()
is called on the dialog, if the last empty line edit is filled, and Enter is pressed on keyboard the QDialog closes.
I actually want to avoid this so only a mouse click on the submitQPushButton
will close the QDialog.Any suggestions how to achieve this?
Thanks
-
Hi,
My platform: Linux kubuntu
QT version: 4.7.1I am trying to achieve the following:
I have a simple QDialog with 4 QLineEdits and 2 QPushButtons for submit and reject.
The 4 QLineEdits are connected to a slot as follows:connect(m_line_edit_1, SIGNAL(returnPressed()), this, SLOT(checkLineEdits()) connect(m_line_edit_2, SIGNAL(returnPressed()), this, SLOT(checkLineEdits()) connect(m_line_edit_3, SIGNAL(returnPressed()), this, SLOT(checkLineEdits()) connect(m_line_edit_4, SIGNAL(returnPressed()), this, SLOT(checkLineEdits())
where the slots performs the following:
void checkLineEdits() { bool disable_submit = m_line_edit_1->text().isEmpty() || m_line_edit_2->text().isEmpty() || m_line_edit_3->text().isEmpty() || m_line_edit_4->text().isEmpty(); m_submit_button->setEnabled(false == disable_submit); }
My problem is, after
exec()
is called on the dialog, if the last empty line edit is filled, and Enter is pressed on keyboard the QDialog closes.
I actually want to avoid this so only a mouse click on the submitQPushButton
will close the QDialog.Any suggestions how to achieve this?
Thanks
@walle19 said in QDialog closed unexpectedly:
My problem is, after exec() is called on the dialog, if the last empty line edit is filled, and Enter is pressed on keyboard the QDialog closes.
Nothing in the code you show should cause this. So there is probably more to it....
You show nothing about whatever you are doing about "reject". All you show is code to enable/disable a button.
Pressing "Enter" on a dialog where the focus is on one of its ("accept"/"reject") buttons causes aQDialog::exec()
to exit and close it, as you would expect. Maybe that is only the case after you have filled in the lastQLineEdit
?I actually want to avoid this so only a mouse click on the submit QPushButton will close the QDialog.
Look it up in
QDialog
docs. I think you want it so the button is not a default button, meaning that "Enter" would action it which you do not want. Or maybe prevent the button from ever accepting focus, then "Enter" won't work on it and the user would have to click it. -
My "Cancel" QPushButton slot only calls
reject()
without any special additions.If I set the submit button focus policy to
Qt::NoFocus
then indeed after pressing enter to submit the last empty line edit, theQDialog
isn't closed until the Submit button is pressed.Thanks a-lot.