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();
});
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();
});
To copy to clipboard, switch view to plain text mode
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();
m_Browser->page()->runJavaScript("document.querySelector('img');", [&] (const QVariant &result) {
qDebug()<< result << result.toByteArray();
To copy to clipboard, switch view to plain text mode
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.
Bookmarks