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. How to realize the cancel operation of setting/option dialog?
Forum Updated to NodeBB v4.3 + New Features

How to realize the cancel operation of setting/option dialog?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 220 Views 1 Watching
  • 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.
  • LimerL Offline
    LimerL Offline
    Limer
    wrote on last edited by
    #1

    Every app has it's setting/option dialog. In this dialog, it has many widgets, such as, pushbutton, groupbox, lineedit, combobox,etc.

    If ths user update these widgets' contents in setting/option dialog, but click cancel pushbutton to undo the previous error/wrong operations.

    The setting/option dialog should keep the original state when next dialog 's opening.

    My solution is using extra variables to save these widgets' contents in setting/option dialog, such as, bool variable to save QGroupBox, int variable to save QComboBox, QString variable to save QLineEdit/QTextEdit,

    Just like,

    class OptionDialog : public QDialog {
    .....
    private:
    
    QLineEdit*     m_hostLineEdit;
    QLineEdit*     m_portLineEdit;
    QLineEdit*     m_userLineEdit;
    QLineEdit*     m_pwdLineEdit;
    
    QString        m_host; // to save m_hostLineEdit
    QString        m_port; // to save m_portLineEdit
    QString        m_username; // to save m_userLineEdit
    QString        m_password; // to save m_pwdLineEdit
    .....
    
    
    void ok() // when clicked the ok pushbutton
    {
        .......
    
        /* save */
        m_host = m_hostLineEdit->text();
        m_port = m_portLineEdit->text();
        m_username = m_userLineEdit->text();
        m_password = m_pwdLineEdit->text();
    
        ..............
    }
    
    void cancel()  // when clicked the cancel pushbutton
    {
    
        .....
    
        // undo
        m_hostLineEdit->setText(m_host);
        m_portLineEdit->setText(m_port);
        m_userLineEdit->setText(m_username);
        m_pwdLineEdit->setText(m_password);
    
        .......
    }
    
    } // class OptionDialog : public QDialog
    

    Is there anything wrong with my solution?

    If a bad solution, could you give me any advice? Thanks a lot in advance.

    K 1 Reply Last reply
    0
    • LimerL Limer

      Every app has it's setting/option dialog. In this dialog, it has many widgets, such as, pushbutton, groupbox, lineedit, combobox,etc.

      If ths user update these widgets' contents in setting/option dialog, but click cancel pushbutton to undo the previous error/wrong operations.

      The setting/option dialog should keep the original state when next dialog 's opening.

      My solution is using extra variables to save these widgets' contents in setting/option dialog, such as, bool variable to save QGroupBox, int variable to save QComboBox, QString variable to save QLineEdit/QTextEdit,

      Just like,

      class OptionDialog : public QDialog {
      .....
      private:
      
      QLineEdit*     m_hostLineEdit;
      QLineEdit*     m_portLineEdit;
      QLineEdit*     m_userLineEdit;
      QLineEdit*     m_pwdLineEdit;
      
      QString        m_host; // to save m_hostLineEdit
      QString        m_port; // to save m_portLineEdit
      QString        m_username; // to save m_userLineEdit
      QString        m_password; // to save m_pwdLineEdit
      .....
      
      
      void ok() // when clicked the ok pushbutton
      {
          .......
      
          /* save */
          m_host = m_hostLineEdit->text();
          m_port = m_portLineEdit->text();
          m_username = m_userLineEdit->text();
          m_password = m_pwdLineEdit->text();
      
          ..............
      }
      
      void cancel()  // when clicked the cancel pushbutton
      {
      
          .....
      
          // undo
          m_hostLineEdit->setText(m_host);
          m_portLineEdit->setText(m_port);
          m_userLineEdit->setText(m_username);
          m_pwdLineEdit->setText(m_password);
      
          .......
      }
      
      } // class OptionDialog : public QDialog
      

      Is there anything wrong with my solution?

      If a bad solution, could you give me any advice? Thanks a lot in advance.

      K Offline
      K Offline
      kenchan
      wrote on last edited by kenchan
      #2

      @Limer
      I think you will find that is really the only way to do it.
      Have local values in the dialog and only update the real ones when the user clicks OK. Or, only transfer the value in the controls when the user clicks OK.

      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