Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. lineEdit.clear() & lineEdit.setText('') Query
Forum Updated to NodeBB v4.3 + New Features

lineEdit.clear() & lineEdit.setText('') Query

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 721 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • monamourM Offline
    monamourM Offline
    monamour
    wrote on last edited by monamour
    #1

    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,

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Using clear in your code base makes the intent more understandable.

      And you can use it with signal and slots directly.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      monamourM 1 Reply Last reply
      5
      • SGaistS SGaist

        Hi,

        Using clear in your code base makes the intent more understandable.

        And you can use it with signal and slots directly.

        monamourM Offline
        monamourM Offline
        monamour
        wrote on last edited by
        #3

        @SGaist Thank you.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          To add to what @SGaist said keep in mind that lineEdit.setText("") will construct a temporary QString 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.

          monamourM 1 Reply Last reply
          5
          • Chris KawaC Chris Kawa

            To add to what @SGaist said keep in mind that lineEdit.setText("") will construct a temporary QString 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.

            monamourM Offline
            monamourM Offline
            monamour
            wrote on last edited by
            #5

            @Chris-Kawa Many thanks, so to use the clear() function it would be better than setText().

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved