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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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"); 
You say you're trying to append text, but then you simply replace the text. If you want to append the text, you need to set the text to ( the_existing_text + the_new_text) .

Something like:

1
2
3
4
5
6
7
8
ui->displayBrowser->setText(ui->displayBrowser->toPlainText() 
                            + "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");



Last edited on
Hi Repeater, thanks for the replying. Unfortunately it has not worked.
I disagree. I think it does work. Do you have any evidence to support your claim that it didn't work?
while (table[index] != NULL)
when that loop ends `table[index]' will be null
then you try to dereference a null pointer.
Topic archived. No new replies allowed.