我正在尝试将 QWebElement 渲染到 QWidget 中,但是我的应用程序崩溃了,但是如果我将它渲染到 QImage 中,一切都很好。
这是我的代码:
// using this code my application is crashing
void ImageWidget::paintEvent(QPaintEvent *)
{
if (this->imgElement != NULL)
{
QPainter p(this);
this->imgElement->render(&p);
p.end();
}
}
// using this one everything works OK
void ImageWidget::saveImage(QWebElement *el)
{
this->imgElement = el;
QImage m_image = QImage(290, 80, QImage::Format_ARGB32_Premultiplied);
m_image.fill(Qt::transparent);
QPainter p(&m_image);
el->render(&p);
p.end();
m_image.save("some_file.png", "png");
this->update();
}
我在 Win 7 (x64) 上使用 Qt 4.7.3。让我知道我该如何解决这个问题。