0

Now, I have a widget that used for conguring some parameters, There were some QlineEdit with default value and a save button on this widget. People may change the content of QlineEdit. And click the save button, so that the modified parameters can take effect. Here is my question:

How do retrieve changes in the content of all text line edit in this QWidget?

Once I know which edit content has changed, I can judge whether the modified values is legal, and then let the change take effect.

Can anyone give me some ideas?

  • OS: Windows10
  • QT: qt 5.9.0
eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

For this situation, It's better to do one more step before manually validating the user's input. The step is to limit the user to enter invalid settings. If your setting value is a number, use QSpinBox or QDoubleSpinBox for floating-point values. If you want to let the user select from multiple predefined values, like gender(Male, Female), use QComboBox or QRadioButton and so forth. Here is the list of Qt's widgets. So bear in mind, using QLineEdit for all of the inputs is not a good idea.

If your input is something more complex, you can use validators. For getting the idea see this question.

At last, you connect the save button's clicked signal to the slot defined in your widget class using Qt's signals and slots mechanism and get values from all of your inputs and check them, and if everything is OK, apply them to your system.

s4eed
  • 7,173
  • 9
  • 67
  • 104
  • Thanks for your answer! I have other problem that is how do I know that the content of the `textBox` or `QcomboBox` has changed without comparing the content of the control with the previous value. You know if the setting paramters are not changed, I don't need to apply these setting again. However, I have a lot of configuration items, and it seems a bit too complicated to judge one by one . – gavin_free Jan 21 '21 at 10:58
  • @gavin_free QComboBox has few signals which let you know it has changed. See the documentation. It's not needed to compare. Mail me if you want... – s4eed Jan 23 '21 at 03:47