Results 1 to 5 of 5

Thread: Enabling buttons when lineEdit has text

  1. #1
    Join Date
    Feb 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Enabling buttons when lineEdit has text

    Hi there folks,

    I wrote a piece of code that is supposed to put a button enabled (previously grayed out)

    declaration:

    Qt Code:
    1. public slots:
    2. void allowinput();
    3. signals:
    4. void allfieldsfull();
    To copy to clipboard, switch view to plain text mode 

    implementation:

    Qt Code:
    1. adddialog::adddialog() {
    2. setupUi(this);
    3. connect (this, SIGNAL (allfieldsfull()), this, SLOT (allowinput()));
    4. connect (pushButton_Cancel, SIGNAL (clicked()), this, SLOT (close()));
    5. if (lineEdit_name->text() != " ") {
    6. emit allfieldsfull();
    7. }
    8. }
    9.  
    10. void adddialog::allowinput() {
    11. pushButton_ok->setEnabled(true);
    12. }
    To copy to clipboard, switch view to plain text mode 

    the problem is: it's not working!

    any solutions? code samples would be very much appreciated.

    Thanks in advance,

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Enabling buttons when lineEdit has text

    Quote Originally Posted by k12yp70n View Post
    any solutions?
    Yes, read about signals and slots in the documentation, seems you haven't understand the concept right.

    Use textChanged() signal of the line edit, connect it to your slot, check the value and alter the state of your button.

  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Enabling buttons when lineEdit has text

    if (lineEdit_name->text() != " ") {
    emit allfieldsfull();
    }
    also dont use like this condition ..

    use
    QString text = lineEdit_name->text();
    if (!text.isEmpty())
    emit allfieldsfull();
    "Behind every great fortune lies a crime" - Balzac

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Enabling buttons when lineEdit has text

    Quote Originally Posted by wagmare View Post
    QString text = lineEdit_name->text();
    if (!text.isEmpty())
    emit allfieldsfull();
    Qt Code:
    1. if (!lineEdit_name->text().isEmpty())
    2. emit allfieldsfull();
    To copy to clipboard, switch view to plain text mode 
    Is even more better because of avoiding a temporary variable. But nonetheless in that case a signal is not necessary, because you can simply call your member function.

  5. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Enabling buttons when lineEdit has text


    if (!lineEdit_name->text().isEmpty())
    yes i know this is more simpler ... but for newbie i explained clearly that we check in QString function ..

    and see i use "also" .. to tell him in future u use conditions like this in different application ..
    here using textChanged() signal is the better one ... i agree ...
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. QItemDelegate and enabling buttons
    By T4ng10r in forum Qt Programming
    Replies: 0
    Last Post: 8th April 2009, 15:01
  3. Lineedit text change signal
    By zgulser in forum Qt Tools
    Replies: 2
    Last Post: 19th January 2009, 13:38
  4. Replies: 5
    Last Post: 1st February 2008, 18:10
  5. widget for text AND buttons
    By nongentesimus in forum Newbie
    Replies: 2
    Last Post: 16th June 2006, 13:43

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.