Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQValidator Class Reference

The TQValidator class provides validation of input text. More...

#include <qvalidator.h>

Inherits TQObject.

Inherited by TQIntValidator, TQDoubleValidator, and TQRegExpValidator.

List of all member functions.

Public Members


Detailed Description

The TQValidator class provides validation of input text.

The class itself is abstract. Two subclasses, TQIntValidator and TQDoubleValidator, provide basic numeric-range checking, and TQRegExpValidator provides general checking using a custom regular expression.

If the built-in validators aren't sufficient, you can subclass TQValidator. The class has two virtual functions: validate() and fixup().

validate() must be implemented by every subclass. It returns Invalid, Intermediate or Acceptable depending on whether its argument is valid (for the subclass's definition of valid).

These three states require some explanation. An Invalid string is clearly invalid. Intermediate is less obvious: the concept of validity is slippery when the string is incomplete (still being edited). TQValidator defines Intermediate as the property of a string that is neither clearly invalid nor acceptable as a final result. Acceptable means that the string is acceptable as a final result. One might say that any string that is a plausible intermediate state during entry of an Acceptable string is Intermediate.

Here are some examples:

fixup() is provided for validators that can repair some user errors. The default implementation does nothing. TQLineEdit, for example, will call fixup() if the user presses Enter (or Return) and the content is not currently valid. This allows the fixup() function the opportunity of performing some magic to make an Invalid string Acceptable.

TQValidator is typically used with TQLineEdit, TQSpinBox and TQComboBox.

See also Miscellaneous Classes.


Member Type Documentation

TQValidator::State

This enum type defines the states in which a validated string can exist.


Member Function Documentation

TQValidator::TQValidator ( TQObject * parent, const char * name = 0 )

Sets up the validator. The parent and name parameters are passed on to the TQObject constructor.

TQValidator::~TQValidator ()

Destroys the validator, freeing any storage and other resources used.

void TQValidator::fixup ( TQString & input ) const [virtual]

This function attempts to change input to be valid according to this validator's rules. It need not result in a valid string: callers of this function must re-test afterwards; the default does nothing.

Reimplementations of this function can change input even if they do not produce a valid string. For example, an ISBN validator might want to delete every character except digits and "-", even if the result is still not a valid ISBN; a surname validator might want to remove whitespace from the start and end of the string, even if the resulting string is not in the list of accepted surnames.

State TQValidator::validate ( TQString & input, int & pos ) const [pure virtual]

This pure virtual function returns Invalid if input is invalid according to this validator's rules, Intermediate if it is likely that a little more editing will make the input acceptable (e.g. the user types '4' into a widget which accepts integers between 10 and 99) and Acceptable if the input is valid.

The function can change input and pos (the cursor position) if it wants to.

Reimplemented in TQIntValidator, TQDoubleValidator, and TQRegExpValidator.


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8