[−][src]Struct qt_gui::QRegExpValidator
The QRegExpValidator class is used to check a string against a regular expression.
C++ class: QRegExpValidator
.
The QRegExpValidator class is used to check a string against a regular expression.
QRegExpValidator uses a regular expression (regexp) to determine whether an input string is Acceptable, Intermediate, or Invalid. The regexp can either be supplied when the QRegExpValidator is constructed, or at a later time.
When QRegExpValidator determines whether a string is Acceptable or not, the regexp is treated as if it begins with the start of string assertion (^) and ends with the end of string assertion ($); the match is against the entire input string, or from the given position if a start position greater than zero is given.
If a string is a prefix of an Acceptable string, it is considered Intermediate. For example, "" and "A" are Intermediate for the regexp [A-Z][0-9] (whereas "_" would be Invalid).
For a brief introduction to Qt's regexp engine, see QRegExp.
Example of use:
// regexp: optional '-' followed by between 1 and 3 digits QRegExp rx("-?\d{1,3}"); QValidator *validator = new QRegExpValidator(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 QRegExp rx("[1-9]\d{0,3}"); // the validator treats the regexp as "^[1-9]\d{0,3}$" QRegExpValidator v(rx, 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
rx.setPattern("\S+"); // one or more non-whitespace characters v.setRegExp(rx); 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 rx.setPattern("[A-C]\d{5}[W-Z]"); v.setRegExp(rx); 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 rx.setPattern("read\S?me(.(txt|asc|1st))?"); rx.setCaseSensitive(false); v.setRegExp(rx); 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 QRegExpValidator
[src]
pub fn reg_exp_changed(&self) -> Signal<(*const QRegExp,)>
[src]
This property holds the regular expression used for validation
Returns a built-in Qt signal QRegExpValidator::regExpChanged
that can be passed to qt_core::Signal::connect
.
This property holds the regular expression used for validation
By default, this property contains a regular expression with the pattern .*
that matches any string.
Access functions:
const QRegExp & | regExp() const |
void | setRegExp(const QRegExp &rx) |
Notifier signal:
void | regExpChanged(const QRegExp ®Exp) |
pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>
[src]
Calls C++ function: virtual const QMetaObject* QRegExpValidator::metaObject() const
.
pub unsafe fn from_q_object(
parent: impl CastInto<MutPtr<QObject>>
) -> QBox<QRegExpValidator>
[src]
parent: impl CastInto<MutPtr<QObject>>
) -> QBox<QRegExpValidator>
Constructs a validator with a parent object that accepts any string (including an empty one) as valid.
Calls C++ function: [constructor] void QRegExpValidator::QRegExpValidator(QObject* parent = …)
.
Constructs a validator with a parent object that accepts any string (including an empty one) as valid.
pub unsafe fn from_q_reg_exp_q_object(
rx: impl CastInto<Ref<QRegExp>>,
parent: impl CastInto<MutPtr<QObject>>
) -> QBox<QRegExpValidator>
[src]
rx: impl CastInto<Ref<QRegExp>>,
parent: impl CastInto<MutPtr<QObject>>
) -> QBox<QRegExpValidator>
Constructs a validator with a parent object that accepts all strings that match the regular expression rx.
Calls C++ function: [constructor] void QRegExpValidator::QRegExpValidator(const QRegExp& rx, QObject* parent = …)
.
Constructs a validator with a parent object that accepts all strings that match the regular expression rx.
The match is made against the entire string; e.g. if the regexp is [A-Fa-f0-9]+ it will be treated as ^[A-Fa-f0-9]+$.
pub unsafe fn new() -> QBox<QRegExpValidator>
[src]
The QRegExpValidator class is used to check a string against a regular expression.
Calls C++ function: [constructor] void QRegExpValidator::QRegExpValidator()
.
The QRegExpValidator class is used to check a string against a regular expression.
QRegExpValidator uses a regular expression (regexp) to determine whether an input string is Acceptable, Intermediate, or Invalid. The regexp can either be supplied when the QRegExpValidator is constructed, or at a later time.
When QRegExpValidator determines whether a string is Acceptable or not, the regexp is treated as if it begins with the start of string assertion (^) and ends with the end of string assertion ($); the match is against the entire input string, or from the given position if a start position greater than zero is given.
If a string is a prefix of an Acceptable string, it is considered Intermediate. For example, "" and "A" are Intermediate for the regexp [A-Z][0-9] (whereas "_" would be Invalid).
For a brief introduction to Qt's regexp engine, see QRegExp.
Example of use:
// regexp: optional '-' followed by between 1 and 3 digits QRegExp rx("-?\d{1,3}"); QValidator *validator = new QRegExpValidator(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 QRegExp rx("[1-9]\d{0,3}"); // the validator treats the regexp as "^[1-9]\d{0,3}$" QRegExpValidator v(rx, 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
rx.setPattern("\S+"); // one or more non-whitespace characters v.setRegExp(rx); 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 rx.setPattern("[A-C]\d{5}[W-Z]"); v.setRegExp(rx); 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 rx.setPattern("read\S?me(.(txt|asc|1st))?"); rx.setCaseSensitive(false); v.setRegExp(rx); 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_reg_exp(
rx: impl CastInto<Ref<QRegExp>>
) -> QBox<QRegExpValidator>
[src]
rx: impl CastInto<Ref<QRegExp>>
) -> QBox<QRegExpValidator>
Constructs a validator with a parent object that accepts all strings that match the regular expression rx.
Calls C++ function: [constructor] void QRegExpValidator::QRegExpValidator(const QRegExp& rx)
.
Constructs a validator with a parent object that accepts all strings that match the regular expression rx.
The match is made against the entire string; e.g. if the regexp is [A-Fa-f0-9]+ it will be treated as ^[A-Fa-f0-9]+$.
pub unsafe fn qt_metacall(
&mut self,
arg1: Call,
arg2: c_int,
arg3: impl CastInto<MutPtr<*mut c_void>>
) -> c_int
[src]
&mut self,
arg1: Call,
arg2: c_int,
arg3: impl CastInto<MutPtr<*mut c_void>>
) -> c_int
Calls C++ function: virtual int QRegExpValidator::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3)
.
pub unsafe fn qt_metacast(
&mut self,
arg1: impl CastInto<Ptr<c_char>>
) -> MutPtr<c_void>
[src]
&mut self,
arg1: impl CastInto<Ptr<c_char>>
) -> MutPtr<c_void>
Calls C++ function: virtual void* QRegExpValidator::qt_metacast(const char* arg1)
.
pub unsafe fn reg_exp(&self) -> Ref<QRegExp>
[src]
This property holds the regular expression used for validation
Calls C++ function: const QRegExp& QRegExpValidator::regExp() const
.
This property holds the regular expression used for validation
By default, this property contains a regular expression with the pattern .*
that matches any string.
Access functions:
const QRegExp & | regExp() const |
void | setRegExp(const QRegExp &rx) |
pub unsafe fn set_reg_exp(&mut self, rx: impl CastInto<Ref<QRegExp>>)
[src]
This property holds the regular expression used for validation
Calls C++ function: void QRegExpValidator::setRegExp(const QRegExp& rx)
.
This property holds the regular expression used for validation
By default, this property contains a regular expression with the pattern .*
that matches any string.
Access functions:
const QRegExp & | regExp() const |
void | setRegExp(const QRegExp &rx) |
pub unsafe fn static_meta_object() -> Ref<QMetaObject>
[src]
Returns a reference to the staticMetaObject
field.
pub unsafe fn tr(
s: impl CastInto<Ptr<c_char>>,
c: impl CastInto<Ptr<c_char>>,
n: c_int
) -> CppBox<QString>
[src]
s: impl CastInto<Ptr<c_char>>,
c: impl CastInto<Ptr<c_char>>,
n: c_int
) -> CppBox<QString>
Calls C++ function: static QString QRegExpValidator::tr(const char* s, const char* c, int n)
.
pub unsafe fn tr_utf8(
s: impl CastInto<Ptr<c_char>>,
c: impl CastInto<Ptr<c_char>>,
n: c_int
) -> CppBox<QString>
[src]
s: impl CastInto<Ptr<c_char>>,
c: impl CastInto<Ptr<c_char>>,
n: c_int
) -> CppBox<QString>
Calls C++ function: static QString QRegExpValidator::trUtf8(const char* s, const char* c, int n)
.
pub unsafe fn validate(
&self,
input: impl CastInto<MutRef<QString>>,
pos: impl CastInto<MutRef<c_int>>
) -> State
[src]
&self,
input: impl CastInto<MutRef<QString>>,
pos: impl CastInto<MutRef<c_int>>
) -> State
Reimplemented from QValidator::validate().
Calls C++ function: virtual QValidator::State QRegExpValidator::validate(QString& input, int& pos) const
.
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.
Additionally, if input is not matched, the pos parameter is set to the length of the input parameter.
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 QRegExp::exactMatch().
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
.
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<MutRef<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
.
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
.
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(
&mut self,
arg1: Call,
arg2: c_int,
arg3: impl CastInto<MutPtr<*mut c_void>>
) -> c_int
[src]
&mut self,
arg1: Call,
arg2: c_int,
arg3: impl CastInto<MutPtr<*mut c_void>>
) -> c_int
Calls C++ function: virtual int QValidator::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3)
.
pub unsafe fn qt_metacast(
&mut self,
arg1: impl CastInto<Ptr<c_char>>
) -> MutPtr<c_void>
[src]
&mut self,
arg1: impl CastInto<Ptr<c_char>>
) -> MutPtr<c_void>
Calls C++ function: virtual void* QValidator::qt_metacast(const char* arg1)
.
pub unsafe fn set_locale(&mut 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)
.
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<MutRef<QString>>,
arg2: impl CastInto<MutRef<c_int>>
) -> State
[src]
&self,
arg1: impl CastInto<MutRef<QString>>,
arg2: impl CastInto<MutRef<c_int>>
) -> State
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
.
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 QRegExpValidator
[src]
unsafe fn delete(&mut self)
[src]
Destroys the validator.
Calls C++ function: virtual [destructor] void QRegExpValidator::~QRegExpValidator()
.
Destroys the validator.
impl Deref for QRegExpValidator
[src]
type Target = QValidator
The resulting type after dereferencing.
fn deref(&self) -> &QValidator
[src]
Calls C++ function: QValidator* static_cast<QValidator*>(QRegExpValidator* ptr)
.
impl DerefMut for QRegExpValidator
[src]
fn deref_mut(&mut self) -> &mut QValidator
[src]
Calls C++ function: QValidator* static_cast<QValidator*>(QRegExpValidator* 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)
.
unsafe fn dynamic_cast_mut(ptr: MutPtr<QValidator>) -> MutPtr<QRegExpValidator>
[src]
Calls C++ function: QRegExpValidator* dynamic_cast<QRegExpValidator*>(QValidator* ptr)
.
impl DynamicCast<QRegExpValidator> for QObject
[src]
unsafe fn dynamic_cast(ptr: Ptr<QObject>) -> Ptr<QRegExpValidator>
[src]
Calls C++ function: QRegExpValidator* dynamic_cast<QRegExpValidator*>(QObject* ptr)
.
unsafe fn dynamic_cast_mut(ptr: MutPtr<QObject>) -> MutPtr<QRegExpValidator>
[src]
Calls C++ function: QRegExpValidator* dynamic_cast<QRegExpValidator*>(QObject* 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)
.
unsafe fn static_downcast_mut(
ptr: MutPtr<QValidator>
) -> MutPtr<QRegExpValidator>
[src]
ptr: MutPtr<QValidator>
) -> MutPtr<QRegExpValidator>
Calls C++ function: QRegExpValidator* static_cast<QRegExpValidator*>(QValidator* ptr)
.
impl StaticDowncast<QRegExpValidator> for QObject
[src]
unsafe fn static_downcast(ptr: Ptr<QObject>) -> Ptr<QRegExpValidator>
[src]
Calls C++ function: QRegExpValidator* static_cast<QRegExpValidator*>(QObject* ptr)
.
unsafe fn static_downcast_mut(ptr: MutPtr<QObject>) -> MutPtr<QRegExpValidator>
[src]
Calls C++ function: QRegExpValidator* static_cast<QRegExpValidator*>(QObject* ptr)
.
impl StaticUpcast<QObject> for QRegExpValidator
[src]
unsafe fn static_upcast(ptr: Ptr<QRegExpValidator>) -> Ptr<QObject>
[src]
Calls C++ function: QObject* static_cast<QObject*>(QRegExpValidator* ptr)
.
unsafe fn static_upcast_mut(ptr: MutPtr<QRegExpValidator>) -> MutPtr<QObject>
[src]
Calls C++ function: QObject* static_cast<QObject*>(QRegExpValidator* 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)
.
unsafe fn static_upcast_mut(ptr: MutPtr<QRegExpValidator>) -> MutPtr<QValidator>
[src]
Calls C++ function: QValidator* static_cast<QValidator*>(QRegExpValidator* ptr)
.
Auto Trait Implementations
impl RefUnwindSafe for QRegExpValidator
impl Send for QRegExpValidator
impl Sync for QRegExpValidator
impl Unpin for QRegExpValidator
impl UnwindSafe for QRegExpValidator
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> CastInto<U> for T where
U: CastFrom<T>,
[src]
U: CastFrom<T>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> StaticUpcast<T> for T
[src]
unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>
[src]
unsafe fn static_upcast_mut(ptr: MutPtr<T>) -> MutPtr<T>
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,