Hello!
Is there any way to clean the QLineEdits with little code?
Thanks.
Hello!
Is there any way to clean the QLineEdits with little code?
Thanks.
Have you tried lineEdit->setText("") ?
QLineEdit::clear()
That question actually belongs into the Newbie forum and you should always take a look at the qt documentation before asking .
If I misunderstood your question and you are speaking of Many QLineEditS that you want to clear at once, you should have a function that iterates through the list of QLineEdits and calls the mentioned function on them. Use findChildren for that:
where p is the common parentwidget/ancestor of all the lineedits.Qt Code:
le->clear(); }To copy to clipboard, switch view to plain text mode
Last edited by jpn; 13th May 2008 at 19:07. Reason: missing [code] tags
Yes, better use lineEdit.clear(). But I have many lineEdits to clear and the code would be great. I wanted to know if there is a loop for this.
was easier to use without declaring P. It was thus:
Qt Code:
le->clear(); }To copy to clipboard, switch view to plain text mode
Last edited by jpn; 13th May 2008 at 19:07. Reason: missing [code] tags
Yes, the code above works fine if all Line edits are children or descendants (in terms of parenthood, not inheritance) of the Widget you are calling that function from. In that case the implicit "this" corresponds to p as findChildren() is the same as this->findChildren(). However, if the line edits happen to be in a widget that is not a descendant/child of "this" then you must explicitly specify their ancestor/parent .
foreach(QLineEdit* le, findChildren<QLineEdit*>()) {
le->clear();
}
this code is working and thank you.
but i have some QLineEdit I don't need to clear.
what should be the code?
QLineEdit::clear() is a slot,so you can connect an own-defined signal clearLineEdits to those line edits you want to be cleared at once:
and then if emit the signal somewhere in your code:Qt Code:
//prefferably in constructor: Class::Class() { connect(this, SIGNAL(clearLineEdits()), lineEdit_nr1, SLOT(clear())); ....... connect(this, SIGNAL(clearLineEdits()), lineEdit_nrX, SLOT(clear())); }To copy to clipboard, switch view to plain text mode
Why not simpy a function where you'd put all the line edits to clear?Because signal-slot approach is more flexible,as you can add/remove line edits during runtime.
Last edited by MasterBLB; 5th August 2016 at 07:15.
Bookmarks