Hi. I have problem with QWebView and reading values from elements on it.
My code:
Qt Code:
  1. QFile index("://index.html");
  2. index.open(QIODevice::ReadOnly);
  3. ui->webView->page()->mainFrame()->setHtml(index.readAll());
  4. //ui->webView->page()->mainFrame()->load(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + "/index.html"));
  5. index.close();
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. void DataEditor::on_buttonBox_accepted()
  2. {
  3. m_jsonData = QJsonObject();
  4. QWebElement document = ui->webView->page()->mainFrame()->documentElement();
  5. QWebElementCollection collection = document.findAll("input[type=text]");
  6. foreach(const QWebElement &element, collection)
  7. {
  8. if(!element.attribute("value").isEmpty())
  9. m_jsonData.insert(element.attribute("name"), QJsonValue(element.attribute("value")));
  10. qDebug() << element.attribute("name") << element.hasAttribute("value");
  11. }
  12.  
  13. collection = document.findAll("select");
  14. foreach(const QWebElement &element, collection)
  15. {
  16. if(!element.findFirst("option:checked").attribute("value").isEmpty())
  17. m_jsonData.insert(element.attribute("name"), QJsonValue(element.findFirst("option:checked").attribute("value")));
  18. }
  19. collection = document.findAll("input[type=radio]:checked");
  20. foreach(const QWebElement &element, collection)
  21. {
  22. m_jsonData.insert(element.attribute("name"), QJsonValue(element.attribute("value")));
  23. }
  24.  
  25. collection = document.findAll("input[type=checkbox]:checked");
  26. foreach(const QWebElement &element, collection)
  27. {
  28. m_jsonData.insert(element.attribute("name"), QJsonValue(1));
  29. }
  30. qDebug() << QJsonDocument(m_jsonData).toJson();
  31. emit changeData(m_jsonData);
  32. }
To copy to clipboard, switch view to plain text mode 
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.