I am using Qt 4.8.1 with the evaluateJavaScript function to want to get some DOM elements back into a Qt application. The code I used is :
QVariant paragraphs = view->page()->mainFrame()->evaluateJavaScript("document.getElementsByTagName(\"p\")");
const char* returnTypeName = paragraphs.typeName();
std::cout << "returnTypeName = " << returnTypeName << std::endl;
I find that :
returnTypeName = QVariantMap
However, I do not know the actual return type in the QVariantMap.
I want to know that could I find out the actual type in the returned QVariantMap ? Could I convert the QVariantMap to a QWebElement / QWebElementCollection ? Or how could I use the returned QVariantMap (as I have no experience in using QVariant objects).
Thanks for any suggestion.
The first thing you should do is consult the QVariant documentation. Qt documentation is very comprehensive; make good use of it.
Anyway, a
QVariantMap
is a typedef ofQMap<QString, QVariant>
. So, you use string keys (variable names) to extract individual values.