0

I have a lineEdit I use so the user can enter a frequency interval,

// Making the lineedit objects only accept numbers and align it leftside
ui->frequency->setValidator(new QIntValidator(36, 1000, this));
ui->frequency->setAlignment(Qt::AlignRight);

It works fine to the top limit 1000 but the lower dos not. So I created an slot to control it,

// Control freqeuncy interval
void gui::f_interval()
{
    QString f = ui->frequency->text();
    freq = f.toInt();

    if (freq < 36)
    {
        int status = QMessageBox::warning(this,"Warning","Invalid frequency interval",QMessageBox::Ok);
    }
}

and connected it to the signal of the lineEdit,

// Control frequency interval
connect(ui->frequency, SIGNAL(editingFinished()), this, SLOT(f_interval()));

so that when the user enters a number lower than 36 it gets a warning dialog window.

But it doesn't seem to work. can anyone help me?

SamuelNLP
  • 4,038
  • 9
  • 59
  • 102

1 Answers1

1

You want to connect with textChanged signal instead of editingFinished.

LE: also i don't remember having issues with validator, so can you provide more details, like Qt version, Os version, compiler, maybe see if the issue is reproduced in a sample project.

Zlatomir
  • 6,964
  • 3
  • 26
  • 32
  • if I use the textChanged it won't produce the effect I want. – SamuelNLP Jan 31 '13 at 14:27
  • imagine I want the 300. If i put the first 3 of 300 it will tell me the warning dialog because 3 is lower than 36 – SamuelNLP Jan 31 '13 at 14:28
  • QT 4.8.1, ubuntu 12.04 LTS x86 – SamuelNLP Jan 31 '13 at 14:35
  • Yes, you are right. The issues is that actually the numbers lower are in _Intermediate_ state in validator, so you can either go with checking the state of the validator and maybe you need the focusChanged too (to see if the user changed the focus out of your lineEdit). Or the easy way is to use a [QSpinBox](http://doc.qt.digia.com/qt/qspinbox.html) that is actually built to get numbers as input and has min and max values. – Zlatomir Jan 31 '13 at 14:55
  • can you give some details on using `void QApplication::focusChanged ( QWidget * old, QWidget * now )`? – SamuelNLP Jan 31 '13 at 15:54
  • Use QSpinBox/QDoubleSpinBox in this case which is more handy for such range validation, I think. – Joonhwan Feb 01 '13 at 04:59