Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QPrinter problem in Qt-5.13.0 with Xcode 10.3



  • Hi

    I've just resurrected a piece of software I wrote a couple of years ago. It worked back then under Qt-5.5 (I think). Now I'm getting error messages relating to "Unknown type name 'QPrinter'" under Qt-5.13.0.

    Here is the code fragment with the error messages inserted alongside the code and preceded by an *:

    ...

    #include <QPrinter>
    #include <QPrinterInfo>

    void MainWindow::printHints(Grid *p)
    {
    QPrinterInfo printer; *Unknown type name 'QPrinterInfo'
    int row, col, n, bit;

    if (printer.defaultPrinter().isNull()) {
    statusBar()->showMessage(tr("No printer available."));
    return;
    }
    QPrinter hints; *Unknown type name 'QPrinter'; did you mean 'QPainter'?
    hints.setPageOrientation(QPageLayout::Landscape); *No member named 'setPageOrientation' in 'QPainter'

    QFont printfont("courier", 10);
    printfont.setFixedPitch(true);

    QPainter painter;
    painter.begin(&hints); *Cannot initialize a parameter of type 'QPaintDevice *' with an rvalue of type 'QPainter *'
    ...

    Can anyone explain why QPrinter & QPrinterInfo are unknown types please?



  • Ah ha!

    Solved. I was using the wrong version of qmake to build the project.

    All sorted now.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Do you have QT += printsupport in your .pro file ?



  • @SGaist

    Hi,

    Yes:

    ...
    QT += widgets
    QT += printsupport
    QT += gui
    ...



  • Ah ha!

    Solved. I was using the wrong version of qmake to build the project.

    All sorted now.


Log in to reply