Unsolved Appending text in a QTextEdit
-
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");
-
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.
-
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");
-
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.
-
@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.
-
Hi,
What about QTextEdit::append ?
-
Currently you are overwriting. I know, that you dont want that.
setText
is wrong in your case. You can not use it to keep the output of all indices in yourdisplayBrower
.setText("A"); // TextEdit contains "A" setText("B") // TextEdit contains "B", NOT "AB"
@VRonin s approach should work, if you do it right.