CopperSpice API  1.7.2
QIntValidator Class Reference

The QIntValidator class provides a validator that ensures a string contains a valid integer within a specified range. More...

Inheritance diagram for QIntValidator:
QValidator QObject

Public Signals

void bottomChanged (int newValue)
 
void topChanged (int newValue)
 
- Public Signals inherited from QValidator
void changed ()
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Methods

 QIntValidator (int minimum, int maximum, QObject *parent=nullptr)
 
 QIntValidator (QObject *parent=nullptr)
 
 ~QIntValidator ()
 
int bottom () const
 
void fixup (QString &input) const override
 
void setBottom (int newValue)
 
virtual void setRange (int minimum, int maximum)
 
void setTop (int newValue)
 
int top () const
 
QValidator::State validate (QString &input, int &pos) const override
 
- Public Methods inherited from QValidator
 QValidator (QObject *parent=nullptr)
 
 ~QValidator ()
 
QLocale locale () const
 
void setLocale (const QLocale &locale)
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &objName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Properties

 bottom
 
 top
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Types inherited from QValidator
enum  State
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

The QIntValidator class provides a validator that ensures a string contains a valid integer within a specified range.

QValidator *validator = new QIntValidator(100, 999, this);
QLineEdit *edit = new QLineEdit(this);
// the edit lineedit will only accept integers between 100 and 999
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.

QString str;
int pos = 0;
QIntValidator v(100, 900, this);
str = "1";
v.validate(str, pos); // returns Intermediate
str = "012";
v.validate(str, pos); // returns Intermediate
str = "123";
v.validate(str, pos); // returns Acceptable
str = "678";
v.validate(str, pos); // returns Acceptable
str = "999";
v.validate(str, pos); // returns Intermediate
str = "1234";
v.validate(str, pos); // returns Invalid
str = "-123";
v.validate(str, pos); // returns Invalid
str = "abc";
v.validate(str, pos); // returns Invalid
str = "12cm";
v.validate(str, pos); // returns Invalid

Notice that the value 999 returns Intermediate. Values consisting of a number of digits equal to or less than the max value are considered intermediate. This is intended because the digit that prevents a number to be in range is not necessarily the last digit typed. This also means that an intermediate number can have leading zeros.

The minimum and maximum values are set in one call with setRange(), or individually with setBottom() and setTop().

QIntValidator uses its locale() to interpret the number. For example, in Arabic locales, QIntValidator will accept Arabic digits. In addition, QIntValidator is always guaranteed to accept a number formatted according to the "C" locale.

See also
QDoubleValidator, QRegularExpressionValidator

Constructor & Destructor Documentation

QIntValidator::QIntValidator ( QObject parent = nullptr)
explicit

Constructs a validator with a parent object that accepts all integers.

QIntValidator::QIntValidator ( int  minimum,
int  maximum,
QObject parent = nullptr 
)

Constructs a validator with a parent, that accepts integers from minimum to maximum inclusive.

QIntValidator::~QIntValidator ( )

Destroys the validator.

Method Documentation

int QIntValidator::bottom ( ) const
inline

Returns the value of the property.

void QIntValidator::bottomChanged ( int  newValue)
signal

Documentation pending.

void QIntValidator::fixup ( QString input) const
overridevirtual

Reimplemented from QValidator::fixup().

Reimplemented from QValidator.

void QIntValidator::setBottom ( int  newValue)

Sets the value of the property to newValue.

void QIntValidator::setRange ( int  minimum,
int  maximum 
)
virtual

Sets the range of the validator to only accept integers between minimum and maximum inclusive.

void QIntValidator::setTop ( int  newValue)

Sets the value of the property to newValue.

int QIntValidator::top ( ) const
inline

Returns the value of the property.

void QIntValidator::topChanged ( int  newValue)
signal

Documentation pending.

QValidator::State QIntValidator::validate ( QString input,
int &  pos 
) const
overridevirtual

Reimplemented from QValidator::validate().

Returns Acceptable if the input is an integer within the valid range, Intermediate if the input is a prefix of an integer in the valid range, and Invalid otherwise.

If the valid range consists of just positive integers (e.g., 32 to 100) and input is a negative integer, then Invalid is returned. (On the other hand, if the range consists of negative integers (e.g., -100 to -32) and input is a positive integer, then Intermediate is returned, because the user might be just about to type the minus (especially for right-to-left languages).

int pos = 0;
s = "abc";
v.validate(s, pos); // returns Invalid
s = "5";
v.validate(s, pos); // returns Intermediate
s = "50";
v.validate(s, pos); // returns Acceptable

By default, the pos parameter is not used by this validator.

Implements QValidator.

Property Documentation

QIntValidator::bottom

This property holds the validator's lowest acceptable value.

By default, this property's value is derived from the lowest signed integer available (typically -2147483647).

See also
setRange()
PropertiesClass Methods
read bottom
write setBottom
notify bottomChanged
QIntValidator::top

This property holds the validator's highest acceptable value.

By default, this property's value is derived from the highest signed integer available (typically 2147483647).

See also
setRange()
PropertiesClass Methods
read top
write setTop
notify topChanged