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] Problem when filling value of a textarea loaded into QWebView
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Problem when filling value of a textarea loaded into QWebView

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.2k 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.
  • D Offline
    D Offline
    dolevo
    wrote on 4 May 2014, 06:59 last edited by
    #1

    Hi all,

    I have a target webpage loaded into my QWebView. In this page there is a textarea which I want to fill in from my application dynamically. I use the following code to fill it in:

    @
    void target::HandleTextArea(QWebElement aElement, QString specifier, QString text)
    {
    QString jsCode;
    jsCode = QString("$("#%1").val("%2");").arg(specifier).arg(text);
    aElement.evaluateJavaScript(jsCode);
    }
    @

    So, eventually the above code generates the following JQuery code as an example to be executed:

    @$("#description").val("This is an example text.\n\nThere is multiple of lines here.\nMultiple...\n\nMultiple...");@

    So, as you see, the text has already some \n characters in. Actually this text is coming from my database. However, this code doesn't fill anything into the textarea. If I remote \n characters, it places there just fine but of course there is no newline visible. It comes all in one sentence. I have read a lot of documents, JQuery examples, JS examples where this code should be just fine but it doesn't work in QWebView.

    Can anyone shed some light here?

    1 Reply Last reply
    0
    • C Online
      C Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on 4 May 2014, 09:31 last edited by
      #2

      If your text comes from database then you need to convert actual newline characters into text "\n" (slash and n character), eg.
      @text.replace('\n', "\n");@
      If you don't then you're not injecting this:
      @
      $("#description").val("This is an example text.\n\nThere is multiple of lines here.\nMultiple...\n\nMultiple...");@
      but this:
      @$("#description").val("This is an example text.

      There is multiple of lines here.
      Multiple...

      Multiple...");@

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dolevo
        wrote on 4 May 2014, 09:52 last edited by
        #3

        Thanks Chris,
        That solved my problem. Perfect. Thanks a lot.

        1 Reply Last reply
        0

        1/3

        4 May 2014, 06:59

        • Login

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