C++ (Qt)void MainWindow::on_lineEdit_2_textChanged(const QString &arg1){ if (arg1!="1" || arg1!="2"|| arg1!="0") //если текст не содержит 1 2 или 0 { ui->lineEdit_2->clear(); //то очищаем }}
C++ (Qt)QRegularExpression rx("[012]*");QValidator *validator = new QRegularExpressionValidator(rx, lineEdit);lineEdit->setValidator(validator);
C++ (Qt)void MainWindow::on_lineEdit_2_textChanged(const QString &arg1){ QRegExp re; re.setPattern("[012]"); QRegExpValidator *validator=new QRegExpValidator(re,ui->lineEdit_2); ui->lineEdit_2->setValidator(validator); }
if (arg1.right(1) == "0" || arg1.right(1) == "1" || arg1.right(1) == "2") return; else c_line->setText(arg1.left(arg1.length() - 1));