PDA

View Full Version : QPrinter generates empty page



hayati
11th August 2009, 07:04
Hi,

When i initialize QPrinter object with QPrintDialog (which enables user to select whose prefered printer) printer reports an error indicating it is an empty page. But when i choose a pdf or ps file from the same dialog, QPrinter successfully generates file. Printers are working as i'm able to print generated ps/pdf files. Error only comes when i want to print directly to printers with qt.

My qt version is: qt 4.4.3

code below does not work either:


#include <QApplication>
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QPrinter printer;

QPrintDialog *dialog = new QPrintDialog(&printer, NULL);
dialog->setWindowTitle("Print Dialog");
if (dialog->exec() == QDialog::Accepted) {
QTextDocument doc( "abcd efg" );
doc.print(&printer);
}

return app.exec();
}

Thanks

Hayati

yogeshgokul
11th August 2009, 07:52
You should do some error checking.
Use these steps:
1. Find the state of printer just before printing.

QPrinter::printerState()
2. Check for general connectivity of printer with your machine. Try to print a test page from your machine.
3. Use:

QPrinter::isValid ()

hayati
11th August 2009, 08:40
You should do some error checking.
Use these steps:
1. Find the state of printer just before printing.

QPrinter::printerState()


QPrinter::printerState() is Idle so it's ok to send documents.


2. Check for general connectivity of printer with your machine. Try to print a test page from your machine.

I am able to print documents from the printer.


3. Use:

QPrinter::isValid ()

QPrinter::isValid() returns true.

change log from qt 4.4.3 to 4.5.0 is below (QPrinter):
- QPrinter
* [232415] Fixed a problem that caused a an invalid QPrinter
object to not update its validity after being passed into a
QPrintDialog.
* [215401] Fixed the size of the Executive paper format.
* [202113] Improved speed when printing to a highres PostScript printer.
* [195028] Trying to print to a non-existing file didn't update the validity
of the QPrinter object correctly.
* [134820] Support CUPS printer instances on Unix systems (Mac and X11).
* [201875] Fixed a bug that caused the fill opacity of a brush to be used
for the stroke in certain cases.
* [222056] Fixed absolute letter spacing when printing.
* [234135] Fixed a problem with custom margins for CUPS printers.

does anybody have the same problem with me with the same qt version. i'm not willing to upgrade my qt version.

I should mention that i'm using a network printer, but as i mentioned before i'm able to print documents from this printer.

hayati
11th August 2009, 10:01
in addition,

as i observed so far, i am able to send print jobs to printer (both from cups server and printer status dialog of operating system). but printer complains about empty page. so i suspect about something else other than QPrinter as it's valid and Qt successfully sends document to specified printer. But the problem is, file generated is empty!