QValidator(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

πŸ’– QValidator πŸ’– (aka QValidator(3qt))

okay bestie, buckle up, we're doing Qt's input-text validation class today and it's honestly kind of iconic πŸŽ€


✨ NAME ✨

QValidator β€” validation of input text, fr fr. It checks whether the stuff a user typed is actually, like, okay or not. πŸ’…


🌸 SYNOPSIS 🌸

#include <qvalidator.h>

Inherits QObject. πŸ‘‘

Inherited by QIntValidator, QDoubleValidator, and QRegExpValidator. The whole lil validator family tree 🫢

πŸ¦‹ Public Members

  • QValidator ( QObject * parent, const char * name = 0 ) β€” the constructor, hi bestie πŸ‘‹
  • ~QValidator () β€” the destructor, bye bestie 😭
  • enum State { Invalid, Intermediate, Valid = Intermediate, Acceptable } β€” the three (well, technically four names, but you'll see) vibes a string can be in
  • virtual State validate ( QString & input, int & pos ) const = 0 β€” the pure virtual one, the main character, nobody can skip it ⭐
  • virtual void fixup ( QString & input ) const β€” the little repair-goblin function 🧚

🌈 DESCRIPTION 🌈

The QValidator class provides validation of input text. That's the whole job. She validates. She's a validator. No notes. πŸ’…

The class itself is abstract. Two subclasses, QIntValidator and QDoubleValidator, provide basic numeric-range checking, and QRegExpValidator provides general checking using a custom regular expression. So like, if you want numbers or regex vibes, they already made you one, bestie, don't reinvent her ✨

If the built-in validators aren't sufficient, you can subclass QValidator. 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, so let me lock in πŸ”’. An Invalid string is clearly invalid. Intermediate is less obvious: the concept of validity is slippery when the string is incomplete (still being edited). QValidator 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, because examples ate and left no crumbs:

  • For a line edit that accepts integers from 0 to 999 inclusive, 42 and 123 are Acceptable, the empty string and 1114 are Intermediate and asdf is Invalid.
  • For an editable combobox that accepts URLs, any well-formed URL is Acceptable, "http://www.trolltech.com/," is Intermediate (it might be a cut and paste operation that accidentally took in a comma at the end), the empty string is Intermediate (the user might select and delete all of the text in preparation for entering a new URL), and "http:///./" is Invalid.
  • For a spin box that accepts lengths, "11cm" and "1in" are Acceptable, "11" and the empty string are Intermediate and" http://www.trolltech.com" and "hour" are Invalid.

fixup() is provided for validators that can repair some user errors. The default implementation does nothing. QLineEdit, 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. ✨ magic ✨

QValidator is typically used with QLineEdit, QSpinBox and QComboBox.

See also Miscellaneous Classes.


πŸŽ€ Member Type Documentation

QValidator::State

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

  • QValidator::Invalid β€” the string is clearly invalid. 🚫
  • QValidator::Intermediate β€” the string is a plausible intermediate value during editing. 🚧
  • QValidator::Acceptable β€” the string is acceptable as a final result, i.e. it is valid. βœ…

πŸ’œ MEMBER FUNCTION DOCUMENTATION πŸ’œ

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

Sets up the validator. The parent and name parameters are passed on to the QObject constructor. Handing off the info like a relay race πŸƒβ€β™€οΈ

QValidator::~QValidator ()

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

void QValidator::fixup ( QString & 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. So like, don't just trust her, double-check ngl πŸ™ˆ

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 QValidator::validate ( QString & 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. Yes she can just move your cursor. main character energy fr πŸ‘‘

Reimplemented in QIntValidator, QDoubleValidator, and QRegExpValidator.


🌟 SEE ALSO 🌟


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.


πŸ‘‘ AUTHOR πŸ‘‘

Generated automatically from the source code. (No human wrote this, it simply manifested πŸ’«)


πŸ’€ BUGS πŸ’€

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. (Being a good bug reporter is lowkey a love language 🫢)

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. Not me telling you the man page is the unofficial side quest 😭

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qvalidator.3qt) and the Qt version (3.3.8). Include the receipts, bestie, it helps πŸ’–


and that's the whole page!! this one came from Trolltech AS, dated 2 February 2007, and it's the QValidator(3qt) manual, Qt version 3.3.8 β€” go validate something and slay πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from