Solved

Qt - QRegExp preventing text entry in QLineEdit

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

Accepted Solution

by:
dcoggin1 earned 0 total points
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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 perform CRUD operations on a MySql database.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now