Results 1 to 5 of 5

Thread: QLineEdit problem with setValidator

  1. #1
    Join Date
    Jan 2011
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QLineEdit problem with setValidator

    Hi,

    I have this problem: When I run the program I can not write any text in QLineEdit, if I set a RegExp validator for that, although I can write if I do not set a validator. What do I do wrong?

    Details:

    I have coded exactly the same sample in the book "C++ GUI Programming with Qt4 1st ed" (Blanchette, Summerfield) in the chapter 2, "GoToCell" example.
    In that example, a new class "GoToCellDialog" is created from Ui::GoToCellDialog which inherits QDialog.
    The code in gotocelldialog.cpp is this:

    Qt Code:
    1. #include <QtGui>
    2. #include "gotocelldialog.h"
    3. GoToCellDialog::GoToCellDialog(QWidget *parent)
    4. : QDialog(parent)
    5. {
    6. setupUi(this);
    7. QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
    8. // PROBLEM HERE: lineEdit->setValidator(new QRegExpValidator(regExp, this));
    9. connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
    10. connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
    11. }
    To copy to clipboard, switch view to plain text mode 

    When I set regExp validator, I can not write any text in QLineEdit object.
    However, if I do not set the validator, I can write text.
    This problem occurs, although I have followed the example in the book.
    Why can not I use the validator?
    Any help? Any comment?

    Thank you all.
    Note: I am using Ubuntu 10.x and Qt4 sdk.
    Last edited by wysota; 20th January 2011 at 11:35. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLineEdit problem with setValidator

    Did you set an input mask for the line edit in Designer?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2011
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit problem with setValidator

    Actually, I don't know if it is; the book was not telling any thing about that, so it is remained in its default.
    Now I have looked from the Property Editor. It is like this:

    Property Value
    --------- ------
    inputMask
    translatable Checked
    disambiguation
    comment

    So, it seems that it is not set. Do I have to do some thing?
    Thank you.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLineEdit problem with setValidator

    No, it should be empty. So you say you can't input anything? Not even a single letter?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2011
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit problem with setValidator

    I have added the expressions ([A-Za-z], etc.) step by step and each time I have compiled and run again, and finally it was working with all expressions.
    So rare!
    Thank you much.

Similar Threads

  1. QLineEdit problem
    By kumarpraveen in forum Newbie
    Replies: 5
    Last Post: 12th July 2010, 12:19
  2. QLineEdit Problem
    By newermind in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2009, 14:14
  3. setValidator on QLineEdit
    By osiris81 in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2009, 14:21
  4. problem with QLineEdit and QPalette
    By impeteperry in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2008, 17:05
  5. setValidator
    By :db:sStrong in forum Qt Programming
    Replies: 11
    Last Post: 16th May 2006, 09:59

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.