![]() |
Qt 6.x
The Qt SDK
|
The QDoubleValidator class provides range checking of floating-point numbers. More...
#include <qvalidator.h>
Public Types | |
enum | Notation { StandardNotation , ScientificNotation } |
![]() | |
enum | State { Invalid , Intermediate , Acceptable } |
This enum type defines the states in which a validated string can exist. More... | |
Signals | |
void | bottomChanged (double bottom) |
This signal is emitted after the bottom property changed. | |
void | topChanged (double top) |
This signal is emitted after the top property changed. | |
void | decimalsChanged (int decimals) |
This signal is emitted after the decimals property changed. | |
void | notationChanged (QDoubleValidator::Notation notation) |
This signal is emitted after the notation property changed. | |
![]() | |
void | changed () |
This signal is emitted when any property that may affect the validity of a string has changed. | |
![]() | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
QDoubleValidator (QObject *parent=nullptr) | |
Constructs a validator object with a parent object that accepts any double. | |
QDoubleValidator (double bottom, double top, int decimals, QObject *parent=nullptr) | |
Constructs a validator object with a parent object. | |
~QDoubleValidator () | |
Destroys the validator. | |
QValidator::State | validate (QString &, int &) const override |
Returns \l Acceptable if the string input is in the correct format and contains a double within the valid range. | |
void | fixup (QString &input) const override |
void | setRange (double bottom, double top, int decimals) |
Sets the validator to accept doubles from minimum to maximum inclusive, with at most decimals digits after the decimal point. | |
void | setRange (double bottom, double top) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the validator to accept doubles from minimum to maximum inclusive without changing the number of digits after the decimal point. | |
void | setBottom (double) |
void | setTop (double) |
void | setDecimals (int) |
void | setNotation (Notation) |
double | bottom () const |
double | top () const |
int | decimals () const |
Notation | notation () const |
![]() | |
QValidator (QObject *parent=nullptr) | |
Sets up the validator. | |
~QValidator () | |
Destroys the validator, freeing any storage and other resources used. | |
void | setLocale (const QLocale &locale) |
Sets the locale that will be used for the validator. | |
QLocale | locale () const |
Returns the locale for the validator. | |
virtual State | validate (QString &, int &) const =0 |
This virtual function returns \l Invalid if input is invalid according to this validator's rules, \l Intermediate if it is likely that a little more editing will make the input acceptable (e.g. | |
virtual void | fixup (QString &) const |
This function attempts to change input to be valid according to this validator's rules. | |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Properties | |
double | bottom |
the validator's minimum acceptable value | |
double | top |
the validator's maximum acceptable value | |
int | decimals |
the validator's maximum number of digits after the decimal point | |
Notation | notation |
the notation of how a string can describe a number | |
![]() | |
QString | objectName |
the name of this object | |
Additional Inherited Members | |
![]() | |
void | deleteLater () |
\threadsafe | |
![]() | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
![]() | |
QValidator (QObjectPrivate &d, QObject *parent) | |
QValidator (QValidatorPrivate &d, QObject *parent) | |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
The QDoubleValidator class provides range checking of floating-point numbers.
\inmodule QtGui
QDoubleValidator provides an upper bound, a lower bound, and a limit on the number of digits after the decimal point.
You can set the acceptable range in one call with setRange(), or with setBottom() and setTop(). Set the number of decimal places with setDecimals(). The validate() function returns the validation state.
QDoubleValidator uses its locale() to interpret the number. For example, in the German locale, "1,234" will be accepted as the fractional number 1.234. In Arabic locales, QDoubleValidator will accept Arabic digits.
"C"
locale), the validator will accept group separators. If the string passes validation, pass it to locale().toDouble() to obtain its numeric value.Definition at line 88 of file qvalidator.h.
\value StandardNotation The string is written in the standard format, a whole number part optionally followed by a separator and fractional part, for example {"0.015"}.
\value ScientificNotation The string is written in scientific form, which optionally appends an exponent part to the standard format, for example {"1.5E-2"}.
The whole number part may, as usual, include a sign. This, along with the separators for fractional part, exponent and any digit-grouping, depend on locale. QDoubleValidator doesn't check the placement (which would also depend on locale) of any digit-grouping separators it finds, but it will reject input that contains them if \l QLocale::RejectGroupSeparator is set in locale()
.numberOptions().
Enumerator | |
---|---|
StandardNotation | |
ScientificNotation |
Definition at line 101 of file qvalidator.h.
Constructs a validator object with a parent object that accepts any double.
Definition at line 572 of file qvalidator.cpp.
QDoubleValidator::QDoubleValidator | ( | double | bottom, |
double | top, | ||
int | decimals, | ||
QObject * | parent = nullptr |
||
) |
Constructs a validator object with a parent object.
This validator will accept doubles from bottom to top inclusive, with up to decimals digits after the decimal point.
Definition at line 584 of file qvalidator.cpp.
QDoubleValidator::~QDoubleValidator | ( | ) |
Destroys the validator.
Definition at line 598 of file qvalidator.cpp.
|
inline |
Definition at line 116 of file qvalidator.h.
|
signal |
This signal is emitted after the bottom property changed.
Referenced by setRange().
|
inline |
Definition at line 118 of file qvalidator.h.
References dec.
|
signal |
This signal is emitted after the decimals property changed.
Referenced by setRange().
Attempts to fix the input string to an \l Acceptable representation of a double.
The format of the number is determined by \l notation(), \l decimals(), \l locale() and the latter's \l {QLocale::}{numberOptions()}.
To comply with \l notation(), when \l ScientificNotation is used, the fixed value will be represented in its normalized form, which means that any non-zero value will have one non-zero digit before the decimal point.
To comply with \l decimals(), when it is {-1}
the number of digits used will be determined by \l QLocale::FloatingPointShortest. Otherwise, the fractional part of the number is truncated (with rounding, as appropriate) if its length exceeds \l decimals(). When \l notation() is \l ScientificNotation this is done after the number has been put into its normalized form.
{std::numeric_limits<double>::digits10}
, digits beyond that many in the fractional part may be changed. The resulting string shall encode the same floating-point number, when parsed to a double
. Reimplemented from QValidator.
Definition at line 727 of file qvalidator.cpp.
References d, QLocaleData::DoubleScientificMode, QLocaleData::DoubleStandardMode, QValidator::locale(), and StandardNotation.
QDoubleValidator::Notation QDoubleValidator::notation | ( | ) | const |
Definition at line 890 of file qvalidator.cpp.
References d.
|
signal |
This signal is emitted after the notation property changed.
QDoubleValidator::Notation is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType().
Referenced by setNotation().
void QDoubleValidator::setBottom | ( | double | bottom | ) |
Definition at line 835 of file qvalidator.cpp.
References decimals, setRange(), and top.
void QDoubleValidator::setDecimals | ( | int | decimals | ) |
Definition at line 865 of file qvalidator.cpp.
References bottom, decimals, setRange(), and top.
Definition at line 880 of file qvalidator.cpp.
References QValidator::changed(), d, emit, and notationChanged().
void QDoubleValidator::setRange | ( | double | bottom, |
double | top | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the validator to accept doubles from minimum to maximum inclusive without changing the number of digits after the decimal point.
Definition at line 821 of file qvalidator.cpp.
References decimals, and setRange().
void QDoubleValidator::setRange | ( | double | minimum, |
double | maximum, | ||
int | decimals | ||
) |
Sets the validator to accept doubles from minimum to maximum inclusive, with at most decimals digits after the decimal point.
Definition at line 791 of file qvalidator.cpp.
References bottomChanged(), QValidator::changed(), decimals, decimalsChanged(), emit, and topChanged().
Referenced by setBottom(), setDecimals(), setRange(), and setTop().
void QDoubleValidator::setTop | ( | double | top | ) |
Definition at line 850 of file qvalidator.cpp.
References bottom, decimals, and setRange().
|
inline |
Definition at line 117 of file qvalidator.h.
|
signal |
This signal is emitted after the top property changed.
Referenced by setRange().
|
overridevirtual |
Returns \l Acceptable if the string input is in the correct format and contains a double within the valid range.
Returns \l Intermediate if input is in the wrong format or contains a double outside the range.
Returns \l Invalid if the input doesn't represent a double or has too many digits after the decimal point.
Note: If the valid range consists of just positive doubles (e.g. 0.0 to 100.0) and input is a negative double then \l Invalid is returned. If notation() is set to StandardNotation, and the input contains more digits before the decimal point than a double in the valid range may have, \l Invalid is returned. If notation() is ScientificNotation, and the input is not in the valid range, \l Intermediate is returned. The value may yet become valid by changing the exponent.
By default, the pos parameter is not used by this validator.
Implements QValidator.
Definition at line 629 of file qvalidator.cpp.
References d, QLocaleData::DoubleScientificMode, QLocaleData::DoubleStandardMode, QValidator::locale(), ScientificNotation, and StandardNotation.
|
readwrite |
the validator's minimum acceptable value
By default, this property contains a value of -infinity.
Definition at line 83 of file qvalidator.h.
Referenced by QDoubleValidator(), setDecimals(), and setTop().
|
readwrite |
the validator's maximum number of digits after the decimal point
By default, this property contains a value of -1, which means any number of digits is accepted.
Definition at line 83 of file qvalidator.h.
Referenced by QDoubleValidator(), setBottom(), setDecimals(), setRange(), setRange(), and setTop().
|
readwrite |
the notation of how a string can describe a number
By default, this property is set to ScientificNotation.
Definition at line 83 of file qvalidator.h.
|
readwrite |
the validator's maximum acceptable value
By default, this property contains a value of infinity.
Definition at line 83 of file qvalidator.h.
Referenced by QDoubleValidator(), setBottom(), and setDecimals().