Results 1 to 3 of 3

Thread: simple QDialog with Line validation

  1. #1
    Join Date
    Jul 2009
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Question simple QDialog with Line validation

    Hi,

    I'm attempting to write a simple popup dialog to set up the Hostname and Port for a network connection. I dont really feel like writing a subclass for this, but its turning out to be harder than i thought.

    My problem is that i want the "Save" button to remain disabled until both Validators return acceptable. Here an snippet of the execution block:

    Qt Code:
    1. while(setupDialog->exec())
    2. {
    3. tempHost = hostT->text();
    4. tempPort = portT->text();
    5.  
    6. saveButton->setDisabled(portValidator->validate(tempPort,pos)
    7. ==QValidator::Acceptable &&
    8. hostIPValidator->validate(tempHost,pos)
    9. ==QValidator::Acceptable);
    10. }
    11. if(setupDialog->result() ==QDialog::Accepted)
    12. {
    13. setHostAndPort(hostT->text(),portT->text().toInt());
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    this code is runs, but the save button is Enabled at the start and only gets Disabled if i make a wrong input and after correcting the input it does not become Enabled...

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple QDialog with Line validation

    setupDialog->exec() will return once the dilaog is closed.. so your code within while loop isnt of use..
    What you need to do is connect textChanged() signal of the line edit to some slot, validate the data in that slot and enable/disable the save button.

  3. The following user says thank you to aamer4yu for this useful post:

    ericV (17th August 2009)

  4. #3
    Join Date
    Jul 2009
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: simple QDialog with Line validation

    Thank you! You are absolutely right.

    I wanted to place the entire dialog within one function, but this was not possible for this.
    Had to make two helper slots to communicate between the QLineEdit's and the savebuttons setEnabled Slot.

    Would it be possible to write small functions in the connect call? Instead of actually calling a slot function? (just curious)


    Greets

    Eric

Similar Threads

  1. Why is my application's CPU usage always > 50%
    By richardander in forum Qt Programming
    Replies: 10
    Last Post: 14th October 2010, 22:22
  2. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

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.