I need to control the input that is being provided through a QLineEdit
. The provided input will be checked to see if it meets certain criteria (i.e. particular letters, digits and symbols constraints)
Tasks:
- This checking procedure has to be done when the user is providing input.
- Due to the mismatch with the constraint list, a message should pop-up to notify the user.
My Problem: I only can see how to check the text after the user presses any pushbutton while my goal is to check the input while it is being provided and not have to wait until the button is pressed.
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QString>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString reg_exp("!§$%&/(){}[]=?\ß`*+~#'.,;-@");
int flag = 0;
QString str = ui->lineEdit->text();
for(int i = 0; i < str.length(); ++i)
{
for(int j = 0; j < reg_exp.length(); ++j )
{
if(str[i] == reg_exp[j])
flag = 1;
}
if (flag == 1)
{
QMessageBox::warning(this,"Check","Its a mismatch!");
break;
}
}
}