PDA

View Full Version : QWebView not changing attributes



januszmk
26th March 2013, 14:15
Hi. I have problem with QWebView and reading values from elements on it.
My code:

QFile index("://index.html");
index.open(QIODevice::ReadOnly);
ui->webView->page()->mainFrame()->setHtml(index.readAll());
//ui->webView->page()->mainFrame()->load(QUrl::fromLocalFile(QCoreApplication::applica tionDirPath() + "/index.html"));
index.close();


void DataEditor::on_buttonBox_accepted()
{
m_jsonData = QJsonObject();
QWebElement document = ui->webView->page()->mainFrame()->documentElement();
QWebElementCollection collection = document.findAll("input[type=text]");
foreach(const QWebElement &element, collection)
{
if(!element.attribute("value").isEmpty())
m_jsonData.insert(element.attribute("name"), QJsonValue(element.attribute("value")));
qDebug() << element.attribute("name") << element.hasAttribute("value");
}

collection = document.findAll("select");
foreach(const QWebElement &element, collection)
{
if(!element.findFirst("option:checked").attribute("value").isEmpty())
m_jsonData.insert(element.attribute("name"), QJsonValue(element.findFirst("option:checked").attribute("value")));
}
collection = document.findAll("input[type=radio]:checked");
foreach(const QWebElement &element, collection)
{
m_jsonData.insert(element.attribute("name"), QJsonValue(element.attribute("value")));
}

collection = document.findAll("input[type=checkbox]:checked");
foreach(const QWebElement &element, collection)
{
m_jsonData.insert(element.attribute("name"), QJsonValue(1));
}
qDebug() << QJsonDocument(m_jsonData).toJson();
emit changeData(m_jsonData);
}
The problem is that if I change value of element (input[type=text]) in qwebview, when I am reading data in function on_buttonBox_accepted() - the value is like it was - not changed.
What is causing this? I am using QT 5.0.1.
Thanks in advance.
Regards.