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



  • 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?


  • Moderators

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



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


Log in to reply
 

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