Results 1 to 3 of 3

Thread: Validating QLineEdit

  1. #1
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Validating QLineEdit

    I'm trying to validate the input of a QLineEdit (here lineEdit_new_nickname) with a regular expression, the problem is it seem to be no validator at all, even if ->validator() returns the right QRegExpValidator. I have no idea what the problem could be. The code:

    Qt Code:
    1. IRCSettings::IRCSettings( QWidget *parent) : QWidget(parent) {
    2. setupUi(this);
    3. lastPreferredNickname = NULL;
    4. //TODO: Actually we should set the "11" part after connecting and getting RAW 005 to NICKLEN-1
    5. //QRegExp nick_regexp("[a-zA-Z][a-zA-Z0-9[]\\\\`^{}-]{0,11}");
    6. QRegExpValidator nick_validator(QRegExp("[a-zA-Z][a-zA-Z0-9[]\\\\`^{}-]{0,11}"),this);
    7. lineEdit_new_nickname->setValidator(&nick_validator);
    8. dbg() << "validator:" << lineEdit_new_nickname->validator();
    9.  
    10. dbg() << "connecting toolButton_add_nickname to listWidget_nicknames remove_nickname" <<
    11. connect(listWidget_nicknames,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(remove_preferred_nickname(QListWidgetItem*)));
    12. dbg() << "connecting listWidget_nicknames::widgetsReordered() to this->nicknamesReordered" <<
    13. connect(listWidget_nicknames,SIGNAL(widgetsReordered(QDropEvent*)),this,SLOT(nicknamesReordered(QDropEvent*)));
    14. /**/
    15. }
    To copy to clipboard, switch view to plain text mode 

    Edit: it's not working even with the regexp ".", so the mistake is not there
    Last edited by OriginalCopy; 8th November 2007 at 17:48. Reason: little fix

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Validating QLineEdit

    The validator goes out of scope. Try:
    Qt Code:
    1. QRegExpValidator* nick_validator = new QRegExpValidator(QRegExp("[a-zA-Z][a-zA-Z0-9[]\\\\`^{}-]{0,11}"),this);
    2. lineEdit_new_nickname->setValidator(nick_validator);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Validating QLineEdit

    Thank you.

Similar Threads

  1. Problem Euro Sign with QLineEdit
    By Kubil in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2007, 05:56
  2. QLineEdit and focusInEvent
    By fuzzywuzzy01 in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2007, 00:05
  3. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 02:25
  4. QAction shortcuts from QLineEdit
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 4th March 2007, 16:43
  5. a box around QLineEdit?
    By GreyGeek in forum Qt Tools
    Replies: 13
    Last Post: 8th February 2006, 16:40

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.