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. Appending text in a QTextEdit

Appending text in a QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 3.9k Views
  • 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.
  • J Offline
    J Offline
    jefazo92
    wrote on last edited by VRonin
    #1

    Hi everyone,

    I'm struggling a lot to append the text from a series of object files in an object array. The "display" function as I call it displays the contents of the object stored at a particular index when it is called. I'm using Qt and I'm trying to display my text on a QTextEdit. All items stored in the object are of type QString. Please any help would be really appreciated.

    while (table[index] != NULL){
                if (table[index]->getIDNumber() == idstring){
                    //Return to GUI all members !!!!!!
    
                }
                index = (index + 1)%TABLESIZE;
    
                index = (index + (int)(idNumber/TABLESIZE))%TABLESIZE;
            }
    
            ui->displayBrowser->setText("Hash value: " + QString::number(hashval)
                                        + ", ID No.: " + table[index]->getIDNumber()
                                        + ", Firstname: " + table[index]->getFirstname()
                                        + ", Vehicle: " + table[index]->getLastname()
                                        + ", Address: " + table[index]->getAddress()
                                        + ", Nation: " + table[index]->getNation()
                                        + ", Age: " + table[index]->getAge() + "\n");
    
    Pl45m4P 1 Reply Last reply
    0
    • J jefazo92

      Hi everyone,

      I'm struggling a lot to append the text from a series of object files in an object array. The "display" function as I call it displays the contents of the object stored at a particular index when it is called. I'm using Qt and I'm trying to display my text on a QTextEdit. All items stored in the object are of type QString. Please any help would be really appreciated.

      while (table[index] != NULL){
                  if (table[index]->getIDNumber() == idstring){
                      //Return to GUI all members !!!!!!
      
                  }
                  index = (index + 1)%TABLESIZE;
      
                  index = (index + (int)(idNumber/TABLESIZE))%TABLESIZE;
              }
      
              ui->displayBrowser->setText("Hash value: " + QString::number(hashval)
                                          + ", ID No.: " + table[index]->getIDNumber()
                                          + ", Firstname: " + table[index]->getFirstname()
                                          + ", Vehicle: " + table[index]->getLastname()
                                          + ", Address: " + table[index]->getAddress()
                                          + ", Nation: " + table[index]->getNation()
                                          + ", Age: " + table[index]->getAge() + "\n");
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      Hi @jefazo92

      What exactly is the problem?

      setText will print all properties from your current (indexed) item, but it overwrites the TextEdit, so I guess, you only see the properties from last index?!

      Try to append the the data to a string within your while-loop and then set the whole string to your TextEdit.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        replace

        ui->displayBrowser->setText("Hash value: " + QString::number(hashval)
                                            + ", ID No.: " + table[index]->getIDNumber()
                                            + ", Firstname: " + table[index]->getFirstname()
                                            + ", Vehicle: " + table[index]->getLastname()
                                            + ", Address: " + table[index]->getAddress()
                                            + ", Nation: " + table[index]->getNation()
                                            + ", Age: " + table[index]->getAge() + "\n");
        

        with

        QTextCursor curs(ui->displayBrowser->document());
        curs.insertText("Hash value: " + QString::number(hashval)
                                            + ", ID No.: " + table[index]->getIDNumber()
                                            + ", Firstname: " + table[index]->getFirstname()
                                            + ", Vehicle: " + table[index]->getLastname()
                                            + ", Address: " + table[index]->getAddress()
                                            + ", Nation: " + table[index]->getNation()
                                            + ", Age: " + table[index]->getAge() + "\n");

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        3
        • J Offline
          J Offline
          jefazo92
          wrote on last edited by
          #4

          Hi @Pl45m4 , I don't want to overwrite the textEdit, I want to see all the properties from all indices as they are being printed out.

          Pl45m4P 1 Reply Last reply
          0
          • J Offline
            J Offline
            jefazo92
            wrote on last edited by
            #5

            @VRonin thank you for your post. I tried it but it didn't work. I have also used:

            ui->displayBrowser->setText("Hash value: " + QString::number(hashval)
            + ", ID No.: " + table[index]->getIDNumber()
            + ", Firstname: " + table[index]->getFirstname()
            + ", Vehicle: " + table[index]->getLastname()
            + ", Address: " + table[index]->getAddress()
            + ", Nation: " + table[index]->getNation()
            + ", Age: " + table[index]->getAge() + "\n");

            But the text is still overwriten since the GUI only prints the last entry.
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              What about QTextEdit::append ?

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

              1 Reply Last reply
              4
              • J jefazo92

                Hi @Pl45m4 , I don't want to overwrite the textEdit, I want to see all the properties from all indices as they are being printed out.

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #7

                @jefazo92

                Currently you are overwriting. I know, that you dont want that.
                setTextis wrong in your case. You can not use it to keep the output of all indices in your displayBrower.

                setText("A");
                // TextEdit contains "A"
                setText("B")
                // TextEdit contains "B", NOT "AB"
                
                

                @VRonin s approach should work, if you do it right.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                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