lineEdit.clear() & lineEdit.setText('') Query
Solved
General and Desktop
-
Dear All,
I have small question gentlemen, if I need to clear the fields in "lineEdit" I have used two methods, either by using "lineEdit.clear()" or "lineEdit.setText('')", both of them does clear the fields. The question is what is the difference between them?
Many thanks,
-
Hi,
Using clear in your code base makes the intent more understandable.
And you can use it with signal and slots directly.
-
To add to what @SGaist said keep in mind that
lineEdit.setText("")
will construct a temporaryQString
and this means allocating memory, copying the data from the string literal (the single null terminator in this case), and copying that string into the line edit. A lot of very unnecessary work for clearing. -
@Chris-Kawa Many thanks, so to use the clear() function it would be better than setText().