Solved

Qt - QRegExp preventing text entry in QLineEdit

Posted on 2010-09-11
1
1,185 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
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 columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

696 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