用qt做浏览器实现打印的功能

用qt做了个浏览器,想实现打印jsp页面。但是在实现时,将其做成图片打印有缺陷。后找到
void QWebEnginePage :: print(QPrinter * printer,FunctorOrLambda resultCallback)
void QWebEnginePage :: printToPdf(const QString&filePath,const QPageLayout&pageLayout = QPageLayout(QPageSize(QPageSize :: A4),QPageLayout :: Portrait,QMarginsF()))
这两个方法,但是不会用,输入各种参数后,报各种错。
print方法第二个参数不知道怎么输入,完全不会用。
printToPdf方法,第二个参数是要一个页面布局,但是后面页面大小的方法是什么意思,输入后是错的。报错是: 无法从“QPageSize *”转换为“const QPageLayout”。
我就不懂了,求大神看一下,要怎么弄,指点一下。小弟在此先谢过各位大神了。

m_view->page()->print(printer, [this](bool found) {
if (!found) QMessageBox::information(m_view, QString(), QStringLiteral("No occurrences found"));
});好吧,不是我写错了,是这网站给我吧写的弄没了,现在加上转义

print -----The resultCallback must take a boolean parameter. It will be called with a value of true if the subString was found; otherwise the callback value will be false.
用法实例:
m_view->page()->print(printer, this {
if (!found) QMessageBox::information(m_view, QString(), QStringLiteral("No occurrences found"));
});
printToPdf----This method issues an asynchronous request for printing the web page into a PDF and returns immediately. To be informed about the result of the request, connect to the signal pdfPrintingFinished()
第二个参数不填会以默认A4纸大小打印,打印成功后产生 pdfPrintingFinishe()信号。

NIU FGCH UIO 987Y9 O K I8 H9

** QPrinter printerPixmap(QPrinter::HighResolution);

//自定义纸张大小,这里要打印的内容都在stackedWidget上

printerPixmap.setPageSize(QPrinter::Custom);

printerPixmap.setPaperSize(QSizeF(ui->stackedWidget->height(), ui->stackedWidget->width()), QPrinter::Point);

//设置纸张大小为A4,这里注释掉了,建议自定义纸张 ,否则保存的就会有很多空白

//printerPixmap.setPageSize(QPrinter::A4);

//横向打印

printerPixmap.setOrientation(QPrinter::Landscape);

//设置输出格式为pdf

printerPixmap.setOutputFormat(QPrinter::PdfFormat);

//设置输出路径

printerPixmap.setOutputFileName(fileName); **