[][src]Struct qt_gui::QValidator

#[repr(C)]pub struct QValidator { /* fields omitted */ }

The QValidator class provides validation of input text.

C++ class: QValidator.

C++ documentation:

The QValidator class provides validation of input text.

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.

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. An Invalid string is clearly invalid. Intermediate is less obvious: the concept of validity is difficult to apply 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:

  • For a line edit that accepts integers from 10 to 1000 inclusive, 42 and 123 are Acceptable, the empty string and 5 are Intermediate, and "asdf" and 1114 is Invalid.
  • For an editable combobox that accepts URLs, any well-formed URL is Acceptable, "http://example.com/," is Intermediate (it might be a cut and paste action 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://example.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.

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

QValidator is typically used with QLineEdit, QSpinBox and QComboBox.

Methods

impl QValidator[src]

pub fn changed(&self) -> Signal<()>[src]

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

Returns a built-in Qt signal QValidator::changed that can be passed to qt_core::Signal::connect.

C++ documentation:

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

pub unsafe fn fixup(&self, arg1: impl CastInto<Ref<QString>>)[src]

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.

Calls C++ function: virtual void QValidator::fixup(QString& arg1) const.

C++ documentation:

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.

pub unsafe fn locale(&self) -> CppBox<QLocale>[src]

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

Calls C++ function: QLocale QValidator::locale() const.

C++ documentation:

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

See also setLocale() and QLocale::QLocale().

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QValidator::metaObject() const.

pub unsafe fn qt_metacall(
    &self,
    arg1: Call,
    arg2: c_int,
    arg3: *mut *mut c_void
) -> c_int
[src]

Calls C++ function: virtual int QValidator::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(&self, arg1: *const c_char) -> *mut c_void[src]

Calls C++ function: virtual void* QValidator::qt_metacast(const char* arg1).

pub unsafe fn set_locale(&self, locale: impl CastInto<Ref<QLocale>>)[src]

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

Calls C++ function: void QValidator::setLocale(const QLocale& locale).

C++ documentation:

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

See also locale() and QLocale::setDefault().

pub unsafe fn static_meta_object() -> Ref<QMetaObject>[src]

Returns a reference to the staticMetaObject field.

pub unsafe fn tr(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QValidator::tr(const char* s, const char* c, int n).

pub unsafe fn tr_utf8(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QValidator::trUtf8(const char* s, const char* c, int n).

pub unsafe fn validate(
    &self,
    arg1: impl CastInto<Ref<QString>>,
    arg2: *mut c_int
) -> State
[src]

This 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.

Calls C++ function: pure virtual QValidator::State QValidator::validate(QString& arg1, int& arg2) const.

C++ documentation:

This 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 both input and pos (the cursor position) if required.

Trait Implementations

impl CppDeletable for QValidator[src]

unsafe fn delete(&self)[src]

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

Calls C++ function: virtual [destructor] void QValidator::~QValidator().

C++ documentation:

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

impl Deref for QValidator[src]

type Target = QObject

The resulting type after dereferencing.

fn deref(&self) -> &QObject[src]

Calls C++ function: QObject* static_cast<QObject*>(QValidator* ptr).

impl DynamicCast<QDoubleValidator> for QValidator[src]

unsafe fn dynamic_cast(ptr: Ptr<QValidator>) -> Ptr<QDoubleValidator>[src]

Calls C++ function: QDoubleValidator* dynamic_cast<QDoubleValidator*>(QValidator* ptr).

impl DynamicCast<QIntValidator> for QValidator[src]

unsafe fn dynamic_cast(ptr: Ptr<QValidator>) -> Ptr<QIntValidator>[src]

Calls C++ function: QIntValidator* dynamic_cast<QIntValidator*>(QValidator* ptr).

impl DynamicCast<QRegExpValidator> for QValidator[src]

unsafe fn dynamic_cast(ptr: Ptr<QValidator>) -> Ptr<QRegExpValidator>[src]

Calls C++ function: QRegExpValidator* dynamic_cast<QRegExpValidator*>(QValidator* ptr).

impl DynamicCast<QRegularExpressionValidator> for QValidator[src]

unsafe fn dynamic_cast(ptr: Ptr<QValidator>) -> Ptr<QRegularExpressionValidator>[src]

Calls C++ function: QRegularExpressionValidator* dynamic_cast<QRegularExpressionValidator*>(QValidator* ptr).

impl DynamicCast<QValidator> for QObject[src]

unsafe fn dynamic_cast(ptr: Ptr<QObject>) -> Ptr<QValidator>[src]

Calls C++ function: QValidator* dynamic_cast<QValidator*>(QObject* ptr).

impl StaticDowncast<QDoubleValidator> for QValidator[src]

unsafe fn static_downcast(ptr: Ptr<QValidator>) -> Ptr<QDoubleValidator>[src]

Calls C++ function: QDoubleValidator* static_cast<QDoubleValidator*>(QValidator* ptr).

impl StaticDowncast<QIntValidator> for QValidator[src]

unsafe fn static_downcast(ptr: Ptr<QValidator>) -> Ptr<QIntValidator>[src]

Calls C++ function: QIntValidator* static_cast<QIntValidator*>(QValidator* ptr).

impl StaticDowncast<QRegExpValidator> for QValidator[src]

unsafe fn static_downcast(ptr: Ptr<QValidator>) -> Ptr<QRegExpValidator>[src]

Calls C++ function: QRegExpValidator* static_cast<QRegExpValidator*>(QValidator* ptr).

impl StaticDowncast<QRegularExpressionValidator> for QValidator[src]

unsafe fn static_downcast(
    ptr: Ptr<QValidator>
) -> Ptr<QRegularExpressionValidator>
[src]

Calls C++ function: QRegularExpressionValidator* static_cast<QRegularExpressionValidator*>(QValidator* ptr).

impl StaticDowncast<QValidator> for QObject[src]

unsafe fn static_downcast(ptr: Ptr<QObject>) -> Ptr<QValidator>[src]

Calls C++ function: QValidator* static_cast<QValidator*>(QObject* ptr).

impl StaticUpcast<QObject> for QValidator[src]

unsafe fn static_upcast(ptr: Ptr<QValidator>) -> Ptr<QObject>[src]

Calls C++ function: QObject* static_cast<QObject*>(QValidator* ptr).

impl StaticUpcast<QValidator> for QIntValidator[src]

unsafe fn static_upcast(ptr: Ptr<QIntValidator>) -> Ptr<QValidator>[src]

Calls C++ function: QValidator* static_cast<QValidator*>(QIntValidator* ptr).

impl StaticUpcast<QValidator> for QDoubleValidator[src]

unsafe fn static_upcast(ptr: Ptr<QDoubleValidator>) -> Ptr<QValidator>[src]

Calls C++ function: QValidator* static_cast<QValidator*>(QDoubleValidator* ptr).

impl StaticUpcast<QValidator> for QRegExpValidator[src]

unsafe fn static_upcast(ptr: Ptr<QRegExpValidator>) -> Ptr<QValidator>[src]

Calls C++ function: QValidator* static_cast<QValidator*>(QRegExpValidator* ptr).

impl StaticUpcast<QValidator> for QRegularExpressionValidator[src]

unsafe fn static_upcast(
    ptr: Ptr<QRegularExpressionValidator>
) -> Ptr<QValidator>
[src]

Calls C++ function: QValidator* static_cast<QValidator*>(QRegularExpressionValidator* ptr).

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.