Results 1 to 3 of 3

Thread: QPrinter constructor ignores QPrinterInfo parameter

  1. #1
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default QPrinter constructor ignores QPrinterInfo parameter

    Hi

    I try to construct a QPrinter object that is not the default printer. Thus, I first get the correct QPrinterInfo object and pass it as parameter to the constructor of QPrinter. But QPrinter still ends up with the system-wide default printer. Example code fragment:
    Qt Code:
    1. printerInfo = QPrinterInfo::printerInfo(QStringLiteral("Farbdrucker"));
    2. qDebug() << "printer selected in printerInfo:" << (printerInfo.isNull() ? tr("not set") : tr("%1 (%2)").arg(printerInfo.printerName()).arg(printerInfo.description()));
    3. QPrinter* printer = new QPrinter(printerInfo /*, QPrinter::HighResolution*/);
    4. qDebug() << "selected printer" << printer->printerName();
    To copy to clipboard, switch view to plain text mode 
    The output of the two qDebug() ... statements is as follows (unchanged, whether I include the second parameter to QPrinter or not)
    Qt Code:
    1. printer selected in printerInfo: "Farbdrucker (Brother HL-4150CDN)"
    2. selected printer "TLP2742"
    To copy to clipboard, switch view to plain text mode 
    My conclusions: the QPrinterInfo object is constructed and valid (I have named the printer 'Farbdrucker', German for color printer); QPrinterInfo finds the correct description (make and model of my color printer). But the QPrinter object nevertheless uses the default printer (TLP2742).

    Where is the issue with my code / thinking?

    Versions / OS:
    - Ubuntu 12.04 LTS
    - Qt 5.4

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QPrinter constructor ignores QPrinterInfo parameter

    I cannot see an obvious problem code-wise. Is the colour printer online? Is it available to the user running the code? QPrinter reports the default printer name but which printer does it actually print to?

  3. #3
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QPrinter constructor ignores QPrinterInfo parameter

    @ChrisW67
    Thanks for your hints, how to approach the problem. My extended code snipet now looks as follows:
    Qt Code:
    1. printerInfo = QPrinterInfo::printerInfo(QStringLiteral("Farbdrucker"));
    2. qDebug() << "printer selected in printerInfo:" << (printerInfo.isNull() ? tr("not set") : tr("%1 (%2)").arg(printerInfo.printerName()).arg(printerInfo.description()));
    3. QPrinter* printer = new QPrinter(printerInfo /*, QPrinter::HighResolution*/);
    4. qDebug() << "selected printer" << printer->printerName();
    5. QPainter testPainter;
    6. testPainter.begin(printer);
    7. printer->newPage();
    8. testPainter.end();
    To copy to clipboard, switch view to plain text mode 
    • The color printer is connected and other applications are able to print to it.
    • It attempts to print to the system-wide default printer TLP2742.

    When I select a different printer as system wide default, e.g., print-to-pdf, then the code snipet works properly! Thus, it seems that the issue is specifically with the printer TLP2742 (an offline printer, i.e., it should print to a file). I will further look into this and report back. (I still consider it unexpected behavior / bug that a potentially misconfigured printer TLP2742 messes up the printer selection in a Qt program that deliberately avoids to print to the TLP2742).

    [EDIT]
    I can now confirm that the issue is related to the driver for the default printer that is incomplete or broken. Still not good, of course: this means that an end-user error outside of my control has the potential to break some functionality of my Qt application.
    Last edited by Al_; 27th December 2014 at 15:47.

Similar Threads

  1. Replies: 3
    Last Post: 7th April 2014, 09:43
  2. Replies: 10
    Last Post: 16th September 2013, 11:03
  3. QPrinterInfo - is it possible to recognize a plotter?
    By guest9999 in forum Qt Programming
    Replies: 1
    Last Post: 25th August 2013, 21:40
  4. Replies: 4
    Last Post: 12th August 2008, 01:55
  5. Replies: 2
    Last Post: 24th July 2008, 20:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.