PDA

View Full Version : Getting image directly with runJavaScript



Fred
13th November 2016, 15:12
Hi there,

Firstly some source code:



QWebEngineView *m_Browser = new QWebEngineView(this);

m_Browser->setUrl("http://www.nytimes.com/");

m_Browser->page()->runJavaScript("document.querySelector('img').src;", [&] (const QVariant &result) {
qDebug()<< result << result.toByteArray();
});

With runJavaScript I select the first found image and .src delivers the src tag of the image (e.g. https://static01.nyt.com/images/.....375.jpg). This works very well but if I remove the src tag I get the img object itself.

m_Browser->page()->runJavaScript("document.querySelector('img');", [&] (const QVariant &result) {
qDebug()<< result << result.toByteArray();

QDebug says I get "QVariant(QVariantMap, QMap())", it is possible to convert this response to put it in a QPixmap? I can use the src of the image to load the image but when it is possible to obtain the image directly that would be nice.

anda_skoa
13th November 2016, 15:37
I am not sure, but wouldn't you get the tag object if you don't specify the attribute?

Does the img tag even have the notion of image data that a script could access?

Cheers,
_