[][src]Struct qt_gui::QRegularExpressionValidator

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

The QRegularExpressionValidator class is used to check a string against a regular expression.

C++ class: QRegularExpressionValidator.

C++ documentation:

The QRegularExpressionValidator class is used to check a string against a regular expression.

QRegularExpressionValidator uses a regular expression (regexp) to determine whether an input string is Acceptable, Intermediate, or Invalid. The regexp can either be supplied when the QRegularExpressionValidator is constructed, or at a later time.

If the regexp partially matches against the string, the result is considered Intermediate. For example, "" and "A" are Intermediate for the regexp [A-Z][0-9] (whereas "_" would be Invalid).

QRegularExpressionValidator automatically wraps the regular expression in the \\A and \\z anchors; in other words, it always attempts to do an exact match.

Example of use:

// regexp: optional '-' followed by between 1 and 3 digits QRegularExpression rx("-?\d{1,3}"); QValidator *validator = new QRegularExpressionValidator(rx, this);

QLineEdit *edit = new QLineEdit(this); edit->setValidator(validator);

Below we present some examples of validators. In practice they would normally be associated with a widget as in the example above.

// integers 1 to 9999 QRegularExpression re("[1-9]\d{0,3}"); // the validator treats the regexp as "^[1-9]\d{0,3}$" QRegularExpressionValidator v(re, 0); QString s; int pos = 0;

s = "0"; v.validate(s, pos); // returns Invalid s = "12345"; v.validate(s, pos); // returns Invalid s = "1"; v.validate(s, pos); // returns Acceptable

re.setPattern("\S+"); // one or more non-whitespace characters v.setRegularExpression(re); s = "myfile.txt"; v.validate(s, pos); // Returns Acceptable s = "my file.txt"; v.validate(s, pos); // Returns Invalid

// A, B or C followed by exactly five digits followed by W, X, Y or Z re.setPattern("[A-C]\d{5}[W-Z]"); v.setRegularExpression(re); s = "a12345Z"; v.validate(s, pos); // Returns Invalid s = "A12345Z"; v.validate(s, pos); // Returns Acceptable s = "B12"; v.validate(s, pos); // Returns Intermediate

// match most 'readme' files re.setPattern("read\S?me(.(txt|asc|1st))?"); re.setPatternOptions(QRegularExpression::CaseInsensitiveOption); v.setRegularExpression(re); s = "readme"; v.validate(s, pos); // Returns Acceptable s = "README.1ST"; v.validate(s, pos); // Returns Acceptable s = "read me.txt"; v.validate(s, pos); // Returns Invalid s = "readm"; v.validate(s, pos); // Returns Intermediate

Methods

impl QRegularExpressionValidator[src]

pub fn slot_set_regular_expression(
    &self
) -> Receiver<(*const QRegularExpression,)>
[src]

This property holds the regular expression used for validation

Returns a built-in Qt slot QRegularExpressionValidator::setRegularExpression that can be passed to qt_core::Signal::connect.

C++ documentation:

This property holds the regular expression used for validation

By default, this property contains a regular expression with an empty pattern (which therefore matches any string).

Access functions:

QRegularExpression regularExpression() const
void setRegularExpression(const QRegularExpression &re)

Notifier signal:

void regularExpressionChanged(const QRegularExpression &re)

pub fn regular_expression_changed(&self) -> Signal<(*const QRegularExpression,)>[src]

This property holds the regular expression used for validation

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

C++ documentation:

This property holds the regular expression used for validation

By default, this property contains a regular expression with an empty pattern (which therefore matches any string).

Access functions:

QRegularExpression regularExpression() const
void setRegularExpression(const QRegularExpression &re)

Notifier signal:

void regularExpressionChanged(const QRegularExpression &re)

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

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

pub unsafe fn from_q_object(
    parent: impl CastInto<Ptr<QObject>>
) -> QBox<QRegularExpressionValidator>
[src]

Constructs a validator with a parent object that accepts any string (including an empty one) as valid.

Calls C++ function: [constructor] void QRegularExpressionValidator::QRegularExpressionValidator(QObject* parent = …).

C++ documentation:

Constructs a validator with a parent object that accepts any string (including an empty one) as valid.

pub unsafe fn from_q_regular_expression_q_object(
    re: impl CastInto<Ref<QRegularExpression>>,
    parent: impl CastInto<Ptr<QObject>>
) -> QBox<QRegularExpressionValidator>
[src]

Constructs a validator with a parent object that accepts all strings that match the regular expression re.

Calls C++ function: [constructor] void QRegularExpressionValidator::QRegularExpressionValidator(const QRegularExpression& re, QObject* parent = …).

C++ documentation:

Constructs a validator with a parent object that accepts all strings that match the regular expression re.

pub unsafe fn new() -> QBox<QRegularExpressionValidator>[src]

The QRegularExpressionValidator class is used to check a string against a regular expression.

Calls C++ function: [constructor] void QRegularExpressionValidator::QRegularExpressionValidator().

C++ documentation:

The QRegularExpressionValidator class is used to check a string against a regular expression.

QRegularExpressionValidator uses a regular expression (regexp) to determine whether an input string is Acceptable, Intermediate, or Invalid. The regexp can either be supplied when the QRegularExpressionValidator is constructed, or at a later time.

If the regexp partially matches against the string, the result is considered Intermediate. For example, "" and "A" are Intermediate for the regexp [A-Z][0-9] (whereas "_" would be Invalid).

QRegularExpressionValidator automatically wraps the regular expression in the \\A and \\z anchors; in other words, it always attempts to do an exact match.

Example of use:

// regexp: optional '-' followed by between 1 and 3 digits QRegularExpression rx("-?\d{1,3}"); QValidator *validator = new QRegularExpressionValidator(rx, this);

QLineEdit *edit = new QLineEdit(this); edit->setValidator(validator);

Below we present some examples of validators. In practice they would normally be associated with a widget as in the example above.

// integers 1 to 9999 QRegularExpression re("[1-9]\d{0,3}"); // the validator treats the regexp as "^[1-9]\d{0,3}$" QRegularExpressionValidator v(re, 0); QString s; int pos = 0;

s = "0"; v.validate(s, pos); // returns Invalid s = "12345"; v.validate(s, pos); // returns Invalid s = "1"; v.validate(s, pos); // returns Acceptable

re.setPattern("\S+"); // one or more non-whitespace characters v.setRegularExpression(re); s = "myfile.txt"; v.validate(s, pos); // Returns Acceptable s = "my file.txt"; v.validate(s, pos); // Returns Invalid

// A, B or C followed by exactly five digits followed by W, X, Y or Z re.setPattern("[A-C]\d{5}[W-Z]"); v.setRegularExpression(re); s = "a12345Z"; v.validate(s, pos); // Returns Invalid s = "A12345Z"; v.validate(s, pos); // Returns Acceptable s = "B12"; v.validate(s, pos); // Returns Intermediate

// match most 'readme' files re.setPattern("read\S?me(.(txt|asc|1st))?"); re.setPatternOptions(QRegularExpression::CaseInsensitiveOption); v.setRegularExpression(re); s = "readme"; v.validate(s, pos); // Returns Acceptable s = "README.1ST"; v.validate(s, pos); // Returns Acceptable s = "read me.txt"; v.validate(s, pos); // Returns Invalid s = "readm"; v.validate(s, pos); // Returns Intermediate

pub unsafe fn from_q_regular_expression(
    re: impl CastInto<Ref<QRegularExpression>>
) -> QBox<QRegularExpressionValidator>
[src]

Constructs a validator with a parent object that accepts all strings that match the regular expression re.

Calls C++ function: [constructor] void QRegularExpressionValidator::QRegularExpressionValidator(const QRegularExpression& re).

C++ documentation:

Constructs a validator with a parent object that accepts all strings that match the regular expression re.

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

Calls C++ function: virtual int QRegularExpressionValidator::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* QRegularExpressionValidator::qt_metacast(const char* arg1).

pub unsafe fn regular_expression(&self) -> CppBox<QRegularExpression>[src]

This property holds the regular expression used for validation

Calls C++ function: QRegularExpression QRegularExpressionValidator::regularExpression() const.

C++ documentation:

This property holds the regular expression used for validation

By default, this property contains a regular expression with an empty pattern (which therefore matches any string).

Access functions:

QRegularExpression regularExpression() const
void setRegularExpression(const QRegularExpression &re)

Notifier signal:

void regularExpressionChanged(const QRegularExpression &re)

pub unsafe fn set_regular_expression(
    &self,
    re: impl CastInto<Ref<QRegularExpression>>
)
[src]

This property holds the regular expression used for validation

Calls C++ function: [slot] void QRegularExpressionValidator::setRegularExpression(const QRegularExpression& re).

C++ documentation:

This property holds the regular expression used for validation

By default, this property contains a regular expression with an empty pattern (which therefore matches any string).

Access functions:

QRegularExpression regularExpression() const
void setRegularExpression(const QRegularExpression &re)

Notifier signal:

void regularExpressionChanged(const QRegularExpression &re)

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 QRegularExpressionValidator::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 QRegularExpressionValidator::trUtf8(const char* s, const char* c, int n).

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

Reimplemented from QValidator::validate().

Calls C++ function: virtual QValidator::State QRegularExpressionValidator::validate(QString& input, int& pos) const.

C++ documentation:

Reimplemented from QValidator::validate().

Returns Acceptable if input is matched by the regular expression for this validator, Intermediate if it has matched partially (i.e. could be a valid match if additional valid characters are added), and Invalid if input is not matched.

In case the input is not matched, the pos parameter is set to the length of the input parameter; otherwise, it is not modified.

For example, if the regular expression is \w\d\d (word-character, digit, digit) then "A57" is Acceptable, "E5" is Intermediate, and "+9" is Invalid.

See also QRegularExpression::match().

Methods from Deref<Target = QValidator>

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 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 QRegularExpressionValidator[src]

unsafe fn delete(&self)[src]

Destroys the validator.

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

C++ documentation:

Destroys the validator.

impl Deref for QRegularExpressionValidator[src]

type Target = QValidator

The resulting type after dereferencing.

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

Calls C++ function: QValidator* static_cast<QValidator*>(QRegularExpressionValidator* 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<QRegularExpressionValidator> for QObject[src]

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

Calls C++ function: QRegularExpressionValidator* dynamic_cast<QRegularExpressionValidator*>(QObject* 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<QRegularExpressionValidator> for QObject[src]

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

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

impl StaticUpcast<QObject> for QRegularExpressionValidator[src]

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

Calls C++ function: QObject* static_cast<QObject*>(QRegularExpressionValidator* 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.