Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top