Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-105929

add isEmpty() method to QTextEdit and QPlainTextEdit

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • None
    • All

    Description

      I feel that isEmpty() method is missing in QTextEdit and QPlainTextEdit interface. Checking whether a text edit box is empty is a very frequent operation. As I found people (including me... what a disgrace) tend to abuse toPlainText() or toHtml() to get a string and then check with QString::isEmpty(). Creating the string is however extremely costly operation.

      I know that the best way is probably to check textEdit.document()->isEmpty() but this is somewhat concealed API. I feel isEmpty() should be directly accessible in QTextEdit and QPlainTextEdit API.

      My suggestions:
      1) add QTextEdit::isEmpty()
      2) add QPlainTextEdit::isEmpty()
      3) Warn in documentation for toPlainText() and toHtml() methods against misusing it becase these operations are extremely costly.
      4) add warning to Clazy about misusing toPlainText().isEmpty() or toHtml().isEmpty() or similar (also isNull() etc. and suggest using document()->isEmpty().

      There should be no risk involved, these changes are API extension, so no breaking change.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            vladimir.kraus Vladimir Kraus
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes