Do you understand what virtual method is?
Do you understand what virtual method is?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Yes, I understand that.
Well if you do, then you should be able to answer that:
Since QCombox will call the validate() method of the QValidator instance you gave it, and if is your custom QValidator it will be your version of it.I can't understand how the combo box interacts with it. Is the "validate" method I wrote called behind the scenes?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
frankiefrank (11th October 2012)
First of all, the documentation does not state which data is being validated and when. Does the validation logic fire when I'm leaving focus, when I'm selecting an item from the existing list? When I'm calling addItem / insertItem programatically?
And since you brought up the virtual method: I do have a follow up question. My custom validator validates a string but isn't based on regular expression or on numeric validation. I inherited from RegExpValidator but I don't really understand why I don't see it called:
Qt Code:
// Header { public: }; // Implementation { } { bool valid = someValidationCode(valueToValidate); return valid ? Acceptable : Invalid; }To copy to clipboard, switch view to plain text mode
I don't agree with that statement.First of all, the documentation does not state which data is being validated and when.
If you read the docs for QComboBox::validator() you will see:
So it tells me, that during text input (which es every time you edit the text) the validator will be applied, which, makes sense too.Returns the validator that is used to constrain text input for the combobox.
Now:
That is also in the docs, but you have to pay attention:Does the validation logic fire when I'm leaving focus, when I'm selecting an item from the existing list? When I'm calling addItem / insertItem programatically?
Since we are dealing with an editable QComboBox, it has a QLineEdit.
So it means, when you input text, you are doing the input in to it QLineEdit.
That means, that your validator is applied by the QLineEdit.
Lets see what we can find there:
Ok, I agree, that it doesn't answer your question in a nice one block, and that you have to apply some thought to see how this relates to your case.You can change the text with setText() or insert(). The text is retrieved with text(); the displayed text (which may be different, see EchoMode) is retrieved with displayText(). Text can be selected with setSelection() or selectAll(), and the selection can be cut(), copy()ied and paste()d. The text can be aligned with setAlignment().
When the text changes the textChanged() signal is emitted; when the text changes other than by calling setText() the textEdited() signal is emitted; when the cursor is moved the cursorPositionChanged() signal is emitted; and when the Return or Enter key is pressed the returnPressed() signal is emitted.
When editing is finished, either because the line edit lost focus or Return/Enter is pressed the editingFinished() signal is emitted.
Note that if there is a validator set on the line edit, the returnPressed()/editingFinished() signals will only be emitted if the validator returns QValidator::Acceptable.
But you can't expect the documentation to answer everything in the right way for each case.
But as you can see, the information is there, one just needs to invest in reading it ;-)
Hmm..I inherited from RegExpValidator but I don't really understand why I don't see it called:
How did you check to know if its being called?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
frankiefrank (3rd March 2011)
First of all thank you for your time and attention, and for bringing up the relevant documentation.
I'm sorry but even after reading about the different types of signals emitted from the lineEdit control I can't "guess" the behavior of an editable QComboBox just because it has a lineEdit member. For example, where does it say that validation is even called upon leaving focus of the combo's lineEdit?
I don't expect the documentation to answer "every question" for "every case". I stand by what I said that the documentation about the integration of a validator and a combox is almost not there (unless you know how the combo box wraps the signals emitted from its lineEdit members).
I put a breakpoint in my validate method to see if it's called at any point during my UI/programmatic interaction. I'm not seeing any calls so I'm guessing something in my wiring is wrong.
This piece of documentation:
still leaves me wondering why I'm not seeing the call."Note that if there is a validator set on the line edit, the returnPressed()/editingFinished() signals will only be emitted if the validator returns QValidator::Acceptable."
Here (QLineEdit):For example, where does it say that validation is even called upon leaving focus of the combo's lineEdit?
And since the validator is applied during text input, and because finishing the text input through focus change is part of the input, the validator should be called as result of focus leave.When editing is finished, either because the line edit lost focus or Return/Enter is pressed the editingFinished() signal is emitted.
Ok, that is the right way to do it.I put a breakpoint in my validate method to see if it's called at any point during my UI/programmatic interaction. I'm not seeing any calls so I'm guessing something in my wiring is wrong.
Hmm...
Can you post the code where you set your validator?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Bookmarks