PDA

View Full Version : QLineEdit problem (Jambi)



Binji
12th November 2007, 23:31
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:


if (serverAddress.text().trim()!= "" && serverAddress.text().trim() != null) {
serverNameValid = true;
}else {
errorMessage += "\nServer name cannot be empty!";
}

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.

wysota
13th November 2007, 01:55
Why not do something like this?


connect(serverAddress, SIGNAL(textChanged(const QString &)), this, SLOT(check(const QString &)));
void myClass::check(const QString &str){
button->setEnabled(!str.isEmpty());
}
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.