Mihai Mihai - 27 days ago 14
C++ Question

Qt 5 QWebEngine page printToPdf C2668 ambiguous call to overloaded function

I have the next code:

page.printToPdf("test.pdf");


but when compile it using VS2015 I'm getting this error:

error: C2668: 'QWebEnginePage::printToPdf': ambiguous call to overloaded function


and can't understand why because from the documentation:

printToPdf(const QString &filePath, ...)
printToPdf(FunctorOrLambda resultCallback, ...)

H.G H.G
Answer

This is because both QString and QByteArray have a const char *str constructor. So the compiler can't tell which function to call.

You use QString for your 1st interface, while the 2nd one uses QByteArray. looking at qt docs

The resultCallback must take a const reference to a QByteArray as parameter.

Thus, explicitly passing QString or QByteArray should solve the problem. For example,

QString str = "test.pdf";
page.printToPdf(str);
Comments