Qt Forum

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

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

    General and Desktop
    2
    3
    1018
    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.
    • D
      dolevo last edited by

      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 Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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 Reply Quote 0
        • D
          dolevo last edited by

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

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