[Qt-interest] QValidator::validate() and QLineEdit ... when is it called?

Ellen Kestrel dragonflykes at gmail.com
Sat Feb 5 00:44:13 CET 2011


IIRC, QValidator is mainly for requiring input to match certain regexps, not
for what you're trying to do.  It might be possible to get it to do that,
but I don't know how you would do it, and it seems like if you tried it you
would just be working at odds with the Qt API anyway.  If you want something
to happen with the QLineEdit's text whenever the editingFinished () signal
is emitted, why not just make your own slot to do whatever needs doing and
connect it to the editingFinished () signal?  That way you won't even need
to write your own subclass.

EK

On Fri, Feb 4, 2011 at 5:10 PM, Robert Hairgrove <evorgriahr at hispeed.ch>wrote:

> I am having a problem with unwanted recursion in my custom validator's
> validate() function. Might be a simple (stupid) bug on my part, but I
> think the documentation is somewhat unclear on this.
>
> According to the documentation, as I understand it, the validation
> should only take place after the editing finishes. But as soon as I type
> one character, it is called immediately, and seemingly unendlessly at
> that.
>
> The purpose is to check for an existing file after the user enters a
> path manually. I have set up a browse button which works successfully to
> find a file, but sometimes it is quicker just to change one or two
> characters in an existing file name without going through the open file
> dialog. However, checking should only occur after the user finishes
> editing (i.e. when the editingFinished() signal would normally be
> emitted). My validator class keeps record of the previous value (if any)
> and if the new value is invalid, it should reset the line edit control's
> text to whatever it was before by assigning the non-const argument
> references passed to the validate() function.
>
> Can I use QValidator (i.e. subclass it) for this?
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110204/9ea245e0/attachment.html 


More information about the Qt-interest-old mailing list