好的,在閱讀了一些「相關」問題後,我終於發現唯一的方法可能是JavaScript。
我的解決方案如下。在網站上更改數據後,m_changedInputs包含有關哪些表單和哪些輸入已更改的信息。
CustomWebPage::CustomWebPage(QWidget *parent)
: QWebPage(parent)
{
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
}
...
void CustomWebPage::onLoadFinished(bool ok)
{
// Do nothing on fail
if (!ok)
return;
// Clear all cached data
m_changedInputs.clear();
// Get the main frame
QWebFrame* frame = mainFrame();
frame->addToJavaScriptWindowObject("pluginCreator", this);
// Find the form
QWebElementCollection forms = frame->findAllElements("form");
// Iterate the forms
foreach(QWebElement form, forms) {
// Determine the name of the form
QString formName = form.attribute("name");
// Find the forms' input elements
QWebElementCollection inputs = form.findAll("input");
// Iterate the inputs
foreach(QWebElement input, inputs) {
input.setAttribute("onchange", QString("pluginCreator.onInputChanged(\"%1\", this.name);").arg(formName));
}
}
}
void CustomWebPage::onInputChanged(const QString& formName, const QString& inputName)
{
qDebug() << "Form (" << formName << ") data changed:" << inputName;
// Make sure we only have each input once. A QSet would also do the trick.
QStringList& inputNames = m_changedInputs[formName];
if (!inputNames.contains(inputName))
inputNames.append(inputName);
}
來源
2011-09-01 20:17:21
gri