Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    4
    5572
    Loading More Posts
    • 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.
    • M
      MrNoway last edited by

      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

      1 Reply Last reply Reply Quote 0
      • D
        DerManu last edited by

        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"));
        @

        1 Reply Last reply Reply Quote 0
        • M
          MrNoway last edited by

          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

          1 Reply Last reply Reply Quote 0
          • M
            MrNoway last edited by

            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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post