Results 1 to 3 of 3

Thread: QWebElement setAttribute not working as expected

  1. #1
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QWebElement setAttribute not working as expected

    Not sure what is going on here. I'm loading some HTML in a QWebView and wanting to set the value of a <textarea> field.

    I already have a valid QWebElement reference to the element.

    Doing this does not work:
    QWebElement element = frame->findFirstElement("#myElement");
    element.setAttribute("value", "some value");
    qDebug() << "Attribute is:" << element.attribute("value"); // will output "some value"

    So the attribute is set, but visually the value of the text area is still blank.

    However this does work:
    QWebElement element = frame->findFirstElement("#myElement");
    element.evaluateJavascript("this.value='some value';");

    Now the textarea has "some value" in it as expected.

    Anyone know why the first method doesn't work?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebElement setAttribute not working as expected

    TEXTAREA doesn't use the value attribute of its tag (the syntax is <textarea>content</textarea>). Its javascript object indeed has a value property and that's what you should manipulate and that's what works as you noted yourself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    pherthyl (12th April 2011)

  4. #3
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWebElement setAttribute not working as expected

    Oh yeah. Whoops. Makes sense, thanks.

Similar Threads

  1. Replies: 2
    Last Post: 22nd December 2010, 10:37
  2. Qt Multi-touch Dials example not working as expected
    By dpatel in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2010, 06:50
  3. qmake INSTALLS variable not working as expected
    By andy.fillebrown in forum Newbie
    Replies: 4
    Last Post: 9th November 2010, 16:04
  4. Replies: 0
    Last Post: 17th August 2010, 14:37
  5. QTableView not working as expected.
    By junxuan in forum Qt Programming
    Replies: 7
    Last Post: 30th July 2009, 08:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.