[SOLVED]textBrowser->setText or textEdit->setText Using String Array



  • This Forum seems to be pretty vivid,
    so I hope you can help me with this little problem.

    I do have an array:

    @QString key_storage[20]@

    filled with some values.

    I want them all to be displayed in a textBrowser or textEdit field.

    @ while (j <=i)
    {
    ui.textBrowser->setText( key_storage[j] );

    j++;}@

    if I do like this, it works but the next array is replaced with the before one.

    so I can always just show one line.
    But I want them all.

    How can i do this?

    I am looking for something like a textBrowser->addText command



  • Use QTextEdit::append or build a QString from all strings and then call setText once.

    And once again: Don't use C-Arrays here. You're shooting yourself in the foot. Use QStringList. It could be that easy:
    @
    QStringList strings;
    strings << "line one" << "line two";
    yourTextEdit->setText(strings.join("\n"));
    @



  • hi, thanks for your quick respond,

    I am gonna try it right away.

    okay I will try avoid C-Arrays,
    but thats what I learned the last 2 semesters,
    its hard just to forget it, what those proferssors tried to burn into your mind. -__-

    thank you once again



  • great, that was exactly what I was looking for

    @ QStringList strings;
    for (int b = 0; b<=20; b++){
    strings << key_storage[b]; }
    ui.textEdit->setText(strings.join("\n"));@

    gonna mark is as solved


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.