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. QDialog closed unexpectedly
Forum Update on Monday, May 27th 2025

QDialog closed unexpectedly

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 239 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.
  • W Offline
    W Offline
    walle19
    wrote on last edited by
    #1

    Hi,

    My platform: Linux kubuntu
    QT version: 4.7.1

    I 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 submit QPushButton will close the QDialog.

    Any suggestions how to achieve this?

    Thanks

    JonBJ 1 Reply Last reply
    0
    • W walle19

      Hi,

      My platform: Linux kubuntu
      QT version: 4.7.1

      I 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 submit QPushButton will close the QDialog.

      Any suggestions how to achieve this?

      Thanks

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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 a QDialog::exec() to exit and close it, as you would expect. Maybe that is only the case after you have filled in the last QLineEdit?

      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.

      1 Reply Last reply
      2
      • W Offline
        W Offline
        walle19
        wrote on last edited by
        #3

        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, the QDialog isn't closed until the Submit button is pressed.

        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