Qline edit's Signal is not working as expected



  • Dear All,

    I am trying to develop an application, where in i want to store the user data.
    I have used different lineedits to take the inputs from my user...i have also apply some validators to some lineedit entries....as per expectation the editing finished signal of line edit should not be emitted till the inputs satisfies the validator condition...but in my case focus is shifting to next line edit...creating trouble for me...

    please help me.
    @
    #include "addmemberdlg.h"
    #include "ui_addmemberdlg.h"

    AddMemberDlg::AddMemberDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AddMemberDlg)
    {
    ui->setupUi(this);
    setWindowTitle("ADD MEMBER");

    }

    AddMemberDlg::~AddMemberDlg()
    {
    delete ui;
    }

    void AddMemberDlg::on_pushButton_clicked() //Add Member
    {

        QSqlQuery("SecureFirst");
        QSqlQuery query;
      //  if(ui->comboBox->currentText() == "-")
        //    offval = 0 - offval;
    

    #if 0
    QString cardno;
    QValidator *v;
    int pos;
    //QToolTip ttip;

        v = new QIntValidator(1,99999,this);
        ui->lineEdit_CardNo->setValidator(v);
        ui->lineEdit_CardNo->setMaxLength(5); //Card number of maximum 99999 is allowed
        if(ui->lineEdit_CardNo->text().length() == 5)
            ui->lineEdit_CardNo->setToolTip("Maximum Character Exceeds");
    
        cardno = ui->lineEdit_CardNo->text();
        bool a = cardno.isEmpty();
        if(!a){//if not empty
            int i = v->validate(cardno,pos);
            if((i==0)||(i==1)){ //invalid input
                QMessageBox::information(this,"Add Member Request","Please enter numbers only");//Data Not complete
            }
        }
        else
            QMessageBox::information(this,"Add Member Request","Please enter numbers only");//Data Not complete
    

    #endif

        QString paymode = ui->comboBox->currentText();
        db.transaction();
        query.prepare("UPDATE SecureData SET CardNo=:CardNo, MemberName=:MemberName, Mobile=:Mobile, Address=:Address,SchemeName=:SchemeName, SchemeDuration=:SchemeDuration, Date=:Date, PayMode=:PayMode, Agent=:Agent");
        query.bindValue(":CardNo",cardno);
        query.bindValue(":MemberName",mname);
        query.bindValue(":Mobile",mobile);
        query.bindValue(":Address",address);
        query.bindValue(":SchemeName",schemen);
        query.bindValue(":SchemeDuration",duration);
        query.bindValue(":Date",joining);
        query.bindValue(":PayMode",paymode);
        query.bindValue(":Amount",amount);
        query.bindValue(":Agent",agent);
        query.exec();
    
        db.commit();
        //InitOffsetValues();
        QMessageBox::information(this,"Add Member Request","Data Saved Successfully");//Data Saved
    

    }

    void AddMemberDlg::on_pushButton_2_clicked()//Exit
    {
    reject();
    }

    #if 1
    void AddMemberDlg::on_lineEdit_CardNo_editingFinished()
    {

    QValidator *v;
    int pos;
    //QToolTip ttip;
    QWidget::setAttribute(Qt::WA_AlwaysShowToolTips);
    v = new QIntValidator(1,99999,this);
    ui->lineEdit_CardNo->setValidator(v);
    ui->lineEdit_CardNo->setMaxLength(5); //Card number of maximum 99999 is allowed
    

    // if(ui->lineEdit_CardNo->text().length() == 6)
    // ui->lineEdit_CardNo->setToolTip("Maximum Character Exceeds");

    cardno = ui->lineEdit_CardNo->text();
    bool a = cardno.isEmpty();
    if(!a){//if not empty
        int i = v->validate(cardno,pos);
        if((i==0)||(i==1)){ //invalid input
            QMessageBox::information(this,"Card Number","Please enter numbers only");//Data Not complete
            ui->lineEdit_CardNo->clear();
        }
    }
    else
        QMessageBox::information(this,"Card Number","Please Enter unique Card Number");//Data Not complete
    
    ui->lineEdit_CardNo->setFocus();
    

    }

    void AddMemberDlg::on_lineEdit_MName_editingFinished()
    {

    QString mname = ui->lineEdit_MName->text();
    bool b = mname.isEmpty();
    if(b){//if empty
        QMessageBox::information(this,"Member Name","Field is empty");//Data Not complete
    }
    

    }

    void AddMemberDlg::on_lineEdit_Mobile_editingFinished()
    {

    QString mobile = ui->lineEdit_Mobile->text();
    
    bool c = mobile.isEmpty();
    
    if(!c){//if not empty
        QValidator *validm;
        int pos;
        //QToolTip ttip;
    
        validm = new QIntValidator(1111111111,9999999999,this);
        ui->lineEdit_CardNo->setValidator(validm);
        ui->lineEdit_CardNo->setMaxLength(10); //Mobile number of maximum 99999 is allowed
    
        int i = validm->validate(mobile,pos);
        if((i==0)||(i==1)){ //invalid input
            QMessageBox::information(this,"Mobile Number","Please enter numbers only");//Data Not complete
        }
    }
    else
        QMessageBox::information(this,"Mobile Number","Enter Mobile Number");//Data Not complete
    

    }

    void AddMemberDlg::on_lineEdit_Addr_editingFinished()
    {

    QString address = ui->lineEdit_Addr->text();
    bool d = address.isEmpty();
    if(d){
    
        QMessageBox::information(this,"Address","Address Field is Empty");//Data Not complete
    }
    

    @



  • I think you should create the validators with the line edits as parents

    i.e.

    @...
    ui->lineEdit_CardNo->setValidator(new QIntValidator(1,99999,ui->lineEdit_CardNo));
    ...@


  • Lifetime Qt Champion

    Hi,

    Looking through your code, it seems that you are not yet used to coding a GUI.I would suggest that you first go through some examples/demo of Qt's documentation to see how to use dialogs/designer made uis etc…



  • Hello ,

    You should use lostfocus() signal of those line edit (s) in which you have applied QIntValidator .

    e.g ;

    void MainWindow::on_txtPincode_lostFocus()
    {

    if(ui->txtPincode->text()==0)return;
    
    if(ui->txtPincode->text().length()!=6)
     {
    
         QMessageBox::warning(this,"Invalid PinCode","Must be of 6 digits");
    
         ui->txtPincode->selectAll();
    
         ui->txtPincode->setFocus();
    
     }
    

    }



  • Dear Sir,

    I have just now started in qt...guidance of experts like you definitely means a lot to me....i'll try the suggestions given to me...will be back with more queries for you...thanks all in anticipation.

    Best Regards,
    Gaurav Holey


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.