繁体   English   中英

Qt无法将QPaintDevice转换为QImage

[英]Qt Cannot convert QPaintDevice to QImage

这听起来很愚蠢,但是我无法拍摄QwebView的屏幕截图。

QImage image(view.page()->viewportSize(), QImage::Format_ARGB32);
QPainter painter;
painter.begin(image); // Here is the error. See below
view.page()->mainFrame()->render(&painter);
painter.end();
image.save("out.png");

错误信息是

mainwindow.cpp:115: error: no matching function for call to 'QPainter::begin(QImage&)'
candidate is bool QPainter::begin(QPaintDevice*)

我知道的是,QPaintDevice是QPaint的基础。

从错误中您需要通过指针传递image

painter.begin(&image);

错误消息告诉您:方法begin需要指向绘图表面的指针,而不是引用。 尝试做:

painter.begin(&image);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM