View Full Version : QWebElement setAttribute not working as expected

8th April 2011, 07:50
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?

8th April 2011, 11:28
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.

12th April 2011, 07:17
Oh yeah. Whoops. Makes sense, thanks.