Qt logo

QValidator Class Reference


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

#include <qvalidator.h>

Inherits QObject.

Inherited by QDoubleValidator and QIntValidator.

List of all member functions.

Public Members


Detailed Description

The QValidator class provides validation of input text.

The class itself is abstract; two subclasses provide rudimentary numeric range checking.

The class includes two virtual functions, validate() and fixup().

validate() is pure virtual, so it must be implemented by every subclass. It returns Invalid, Valid or Acceptable depending on whether its argument is valid (for the class' definition of valid).

fixup() is provided for validators that can repair some or all user errors. The default does nothing. QLineEdit, for example, will call fixup() if the user presses Return and the content is not currently valid, in case fixup() can do magic.

QValidator is generally used with QLineEdit, QSpinBox and QComboBox.


Member Function Documentation

QValidator::QValidator ( QWidget * parent, const char * name = 0 )

Sets up the internal data structures used by the validator. At the moment there aren't any.

QValidator::~QValidator ()

Deletes the validator and frees any storage and other resources used.

void QValidator::fixup ( QString & input ) [virtual]

Attempts to change to be valid according to this validator's rules. Need not result in a valid string - callers of this function must re-test afterwards. The default does nothing.

Reimplementation notes:

Note that input may not be the only QString object referencing this string, so it's almost always necessary to detach() the string at the start of the code:

    input.detach();

You can change input even if you aren't able to produce a valid string. For example an ISBN validator might want to delete every character except digits and "-", even if the result is not a valid ISBN, and a last-name validator might want to remove white space from the start and end of the string, even if the resulting string is not in the list of known last names.

QValidator::State QValidator::validate( QString & input, int & pos ) [virtual]

This pure virtual function returns Invalid if input is invalid according to this validator's rules, Valid 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 10-99) and Acceptable if the input is completely acceptable.

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

Reimplemented in QIntValidator and QDoubleValidator.


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-98 Troll Tech, all rights reserved.

It was generated from the following files:


Copyright İ 1998 Troll TechTrademarks
Qt version 1.42