c++qtqvalidator

QIntValidator returns Intermediate in valid input


I have a QIntValidator(int min, int max, QWidget* parent) set-up, but it returns QValidator::Intermediate with inputs that are between min and max (i.e. valid).

I'm using this QIntValidator to check if an input, an integer number, is between the minimum and maximum stabilished. If not, the input is discarded, returning the editor to its previous value.

Imagine that the minimum value is 1 and the maximum is 2147483648. If the user inputs, for example, the number 3, it returns QValidator::Intermediate. This seems like and odd behavior. Any ideas why is this happening?

QLineEdit *lnEdt = reinterpret_cast<QLineEdit*>(item);
QString valData = lnEdt->text(); // "3"
int nRow = ui->listWidget->currentRow();

if(editor == QVariant::Int) //the type of input, in this case, it's true
{
    qDebug() << minimum; //1
    qDebug() << maximum; //2147483648
    QValidator *validator = new QIntValidator(minimum.toInt(), maximum.toInt());
    int pos = 0;
    qDebug() << validator->validate(valData, pos); // QValidator::Intermediate
    if(validator->validate(valData, pos) != QValidator::Acceptable)
    //it falls in this condition, rejecting the input 
    //and setting the editor text to its previous value.
        ui->listWidget->item(nRow)->setText(currentSelectedValue);
}

Solution

  • http://doc.qt.io/qt-5/qintvalidator.html says that this is intended behaviour (length of input is less than length of maximum).