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. [SOLVED] hello world to textEdit text
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] hello world to textEdit text

Scheduled Pinned Locked Moved General and Desktop
13 Posts 6 Posters 19.6k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    alexisdm
    wrote on last edited by
    #4

    Do you mean something like "QTextEdit::append":http://doc.qt.nokia.com/latest/qtextedit.html#append ?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kalster
      wrote on last edited by
      #5

      no. append creates a new line which i want but it appends the first line to the second line, like this...

      hello
      helloworld

      i want just...
      hello
      world

      it would be much easier if i could assign a variable to textEdit like this...
      @tt == ui->textEdit->setHtml("tt");@

      what would be another way for me to code that line above without getting an error?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexisdm
        wrote on last edited by
        #6

        [quote author="kalster" date="1312682966"]no. append creates a new line which i want but it appends the first line to the second line, like this...

        hello
        helloworld[/quote]What code did you use ? Because that works perfectly:
        @ui->textEdit->setText("hello ");
        QString tt = "world";
        ui->textEdit->append(tt);@

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kalster
          wrote on last edited by
          #7

          humm, your right. it does work. I can't remember my code that i used but i must have made a mistake. thank you alexisdm.

          now for my last question. how to get the value of textEdit->setText and store it has a variable. now that i have hello world correctly in the textEdit, i would like to store that result as tt variable. for example...

          @QString tt;
          tt = ui->textEdit->setText();@

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #8

            Have a look at "toHtml()":http://doc.qt.nokia.com/4.7/qtextedit.html#html-prop

            Or you could keep track of what you appended to the QTextEdit yourself in a separate QString.

            Qt Certified Specialist
            www.edalsolutions.be

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kalster
              wrote on last edited by
              #9

              can i have an example on how to use it in a separate Qstring please?

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #10

                Here it is::
                @QString currentText;
                currentText = ui->textEdit->toHtml(); // Or alternatively: currentText = ui->textEdit->toPlainText();
                @

                There also is a method document(), which returns QTextDocument pointer.

                (Z(:^

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kalster
                  wrote on last edited by
                  #11

                  yes. that is what i was looking for. thank you sierdzio

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #12

                    [quote author="kalster" date="1312676984"]
                    @QString tt = "<br>world" ;
                    tt += ui->textEdit->setText("hello ");@
                    [/quote]

                    Time to learn some more basic C++ stuff:

                    operator += takes two arguments of type QString. One is tt, the other should be your expression. Looking at the API docs of "QTextEdit::setText() ":http://doc.qt.nokia.com/4.7/qtextedit.html#plainText-prop shows you that setText returns void. So there is no second argument to operator += and hence the compiler bails out.

                    Methods called setXXX in Qt usually do not return anything. This may be different in other frameworks, but it holds for the vast majority of Qt classes.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kalster
                      wrote on last edited by
                      #13

                      thank you again Volker for your input. I will read everything at the link you gave me very carefully.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved