Mihai Mihai - 2 months ago 24
C++ Question

Qt 5 QWebEngine page printToPdf C2668 ambiguous call to overloaded function

I have the next code:


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, ...)


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";