Solved

Qt - QRegExp preventing text entry in QLineEdit

Posted on 2010-09-11
1
1,211 Views
Last Modified: 2013-11-23
I am a beginner with Qt.  I am working through examples in the C++ GUI Programming with Qt4 book.  In the Chapter 2 GoToCellDialog example I have used Designer to create a small dialog with a QLineEdit (lineEdit) and am adding a regular expression for validation.  Here is the dialog's source code:

#include "gotocelldialog.h"
#include "ui_gotocelldialog.h"

GoToCellDialog::GoToCellDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::GoToCellDialog)
{
    ui->setupUi(this);

    QRegExp regExp("[A-Za-z][1-9][0-9]{0-2}");
    ui->lineEdit->setValidator(new QRegExpValidator (regExp, this));

    connect (ui->okButton, SIGNAL(clicked()), this, SLOT(accept()));
    connect (ui->cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}

void GoToCellDialog::on_lineEdit_textChanged()
{
    ui->okButton->setEnabled(ui->lineEdit->hasAcceptableInput());
}
//  Destructor omitted

When running this in Debug mode I am unable to enter any text in the QLineEdit window.  If I comment out the setValidator call, I am then able to enter text in the window.  I am using QtCreator 2.0.0 which says it is based on Qt 4.7.0.  Thanks for your help.

David
0
Comment
Question by:dcoggin1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
dcoggin1 earned 0 total points
ID: 33653488
My error was in the QRegExp.  I had a dash where I should have had a comma -- {0-2} should have been {0,2}.  I don't think {0-2} is a legal syntax, so I'm surprised it compiled.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question