我正在使用 qt 5.6.2。我想在网页上截屏。这是我正在使用的代码:
#include <QtWidgets/QApplication>
#include <QtWebEngineWidgets/QWebEngineView>
int main(int argc, char *argv[]){
int left, top, width, height;
left = 0;
top = 0;
width = 600;
height = 800;
QApplication a(argc, argv);
QWebEngineView* w = new QWebEngineView();
QImage image(height, width, QImage::Format_RGB32);
QRegion rg(left, top, width, height);
QPainter painter(&image);
w->page()->load(QUrl("https://www.yahoo.com"));
w->show();
w->page()->view()->render(&painter, QPoint(), rg);
painter.end();
image.save("test.png", "PNG", 80);
return a.exec();
}
我运行程序,出现一个窗口,我可以看到yahoo
. 然后我将结果保存到test.png
但那是一张白色的图片。是我无法将结果image
保存到文件还是无法将结果保存image
到文件test.png
以及如何解决?