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. How to judge there is content in QTextEdit?

How to judge there is content in QTextEdit?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 578 Views 1 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by
    #1

    Hi All,
    I'm trying to judge whether there is content in QTextEdit or not.
    If there is content inside, I want to use "append" to show more information in TextEdit.
    If not then I want to use "SetText" to show it.

    How can I do that?
    Is there any element like "isEmpty"?

    JKSHJ 1 Reply Last reply
    0
    • V victor wang

      Hi All,
      I'm trying to judge whether there is content in QTextEdit or not.
      If there is content inside, I want to use "append" to show more information in TextEdit.
      If not then I want to use "SetText" to show it.

      How can I do that?
      Is there any element like "isEmpty"?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @victor-wang said in How to judge there is content in QTextEdit?:

      If there is content inside, I want to use "append" to show more information in TextEdit.
      If not then I want to use "SetText" to show it.

      Why? append() still works when the QTextEdit is empty.

      Is there any element like "isEmpty"?

      Not quite, but you can call textEdit->document()->characterCount();

      Note: Empty documents have characterCount() == 1 (not 0)

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      V 1 Reply Last reply
      3
      • JKSHJ JKSH

        @victor-wang said in How to judge there is content in QTextEdit?:

        If there is content inside, I want to use "append" to show more information in TextEdit.
        If not then I want to use "SetText" to show it.

        Why? append() still works when the QTextEdit is empty.

        Is there any element like "isEmpty"?

        Not quite, but you can call textEdit->document()->characterCount();

        Note: Empty documents have characterCount() == 1 (not 0)

        V Offline
        V Offline
        victor wang
        wrote on last edited by
        #3

        @JKSH
        I did try to use append to show text in empty QTextEdit.
        However, it didn't show anything unless I use "Settext" at the first time then "append".
        This confused me too.
        That's why I try to get another way to solve it.

        JKSHJ 1 Reply Last reply
        0
        • V victor wang

          @JKSH
          I did try to use append to show text in empty QTextEdit.
          However, it didn't show anything unless I use "Settext" at the first time then "append".
          This confused me too.
          That's why I try to get another way to solve it.

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @victor-wang said in How to judge there is content in QTextEdit?:

          However, it didn't show anything unless I use "Settext" at the first time then "append".

          That's strange. Which version of Qt? This code works for me on Qt 5.12.0 (MinGW 7.3.0, 64-bit):

          QTextEdit e;
          e.append("Hello");
          e.show();
          

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          1

          • Login

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