IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QValidator Class

The https:// class provides validation of input text.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QValidator Class▲

  • Header: QValidator

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Gui)

    target_link_libraries(mytarget PRIVATE Qt6::Gui)

  • qmake: QT += gui

  • Inherits: https://

  • Inherited By: https://, https://, and https://

Detailed Description▲

The class itself is abstract. Two subclasses, https:// and https://, provide basic numeric-range checking, and https:// provides general checking using a custom regular expression.

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

https://() must be implemented by every subclass. It returns https://, https:// or https:// depending on whether its argument is valid (for the subclass's definition of valid).

These three states require some explanation. An https:// string is clearly invalid. https:// is less obvious: the concept of validity is difficult to apply when the string is incomplete (still being edited). https:// defines https:// as the property of a string that is neither clearly invalid nor acceptable as a final result. https:// 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 https:// string is https://.

Here are some examples:

  • For a line edit that accepts integers from 10 to 1000 inclusive, 42 and 123 are https://, the empty string, 5, or 1234 are https://, and "asdf" and 10114 is https://.

  • For an editable combobox that accepts URLs, any well-formed URL is https://, "http://example.com/," is https:// (it might be a cut and paste action that accidentally took in a comma at the end), the empty string is https:// (the user might select and delete all of the text in preparation for entering a new URL) and "http:///./" is https://.

  • For a spin box that accepts lengths, "11cm" and "1in" are https://, "11" and the empty string are https://, and "http://example.com" and "hour" are https://.

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

A validator has a locale, set with https://(). It is typically used to parse localized data. For example, https:// and https:// use it to parse localized representations of integers and doubles.

https:// is typically used with QLineEdit, QSpinBox and QComboBox.

See Also▲

See also https://, https://, https://, Line Edits Example

Member Type Documentation▲

 

enum QValidator::State▲

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

Constant

Value

Description

https://::Invalid

0

The string is clearly invalid.

https://::Intermediate

1

The string is a plausible intermediate value.

https://::Acceptable

2

The string is acceptable as a final result; i.e. it is valid.

Member Function Documentation▲

 

[explicit] QValidator::QValidator(QObject *parent = nullptr)▲

Sets up the validator. The parent parameter is passed on to the https:// constructor.

[virtual] QValidator::~QValidator()▲

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

void QValidator::changed()▲

This signal is emitted when any property that may affect the validity of a string has changed.

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

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.

QLocale QValidator::locale() const▲

Returns the locale for the validator. The locale is by default initialized to the same as QLocale().

See Also▲

See also https://(), https://()

void QValidator::setLocale(const QLocale &locale)▲

Sets the locale that will be used for the validator. Unless setLocale has been called, the validator will use the default locale set with https://(). If a default locale has not been set, it is the operating system's locale.

See Also▲

See also https://(), https://()

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

This virtual function returns https:// if input is invalid according to this validator's rules, https:// 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 https:// if the input is valid.

The function can change both input and pos (the cursor position) if required.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.