View Full Version : simple QDialog with Line validation

14th August 2009, 16:18

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:

tempHost = hostT->text();
tempPort = portT->text();

==QValidator::Acceptable &&
if(setupDialog->result() ==QDialog::Accepted)


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...

14th August 2009, 16:41
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.

17th August 2009, 11:10
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)