Results 1 to 2 of 2

Thread: QLineEdit problem (Jambi)

  1. #1
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QLineEdit problem (Jambi)

    First of all hello to everyone. Im still new to Qt but getting better

    And now to my question.. i have a QLineEdit widget which must not be empty when user clicks a certain button. So i wrote this:
    Qt Code:
    1. if (serverAddress.text().trim()!= "" && serverAddress.text().trim() != null) {
    2. serverNameValid = true;
    3. }else {
    4. errorMessage += "\nServer name cannot be empty!";
    5. }
    To copy to clipboard, switch view to plain text mode 
    Simple enough right? But the problem is.. it doesnt work! text() method never returns an empty string even if the QLineEdit widget is empty! Is there anything i missed?

    Thanks for your reply

    edit: I apologize if I shouldnt post Jambi stuff here but didnt see any other appropriate forum.

  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 (Jambi)

    Why not do something like this?

    Qt Code:
    1. connect(serverAddress, SIGNAL(textChanged(const QString &)), this, SLOT(check(const QString &)));
    2. void myClass::check(const QString &str){
    3. button->setEnabled(!str.isEmpty());
    4. }
    To copy to clipboard, switch view to plain text mode 
    It's C++ code, but it's very simple so you should have no trouble translating it to Java. Oh, and check() has to be a slot, of course.

Similar Threads

  1. QLineEdit - lostFocus signal problem
    By Enygma in forum Qt Programming
    Replies: 6
    Last Post: 17th June 2010, 20:52
  2. Problem Euro Sign with QLineEdit
    By Kubil in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2007, 04:56
  3. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 01:25
  4. Problem with QLineEdit and setText
    By Elmo23x in forum Qt Programming
    Replies: 8
    Last Post: 12th April 2007, 12:35
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.