PDA

View Full Version : Printer problem



K4ELO
22nd November 2013, 13:43
Running Qt under Windows and for some reason it can't find the printers (there are 7 including both network and usb printers).

Here's the relevant code:


QT += sql \
printsupport \
serialport \
xml \
network \
widgets


from mainwindow.h
#include <QPrinter>
#include <QPrintDialog>
#include <QPrinterInfo>

from mainwindow.cpp
QList <QPrinterInfo> plist = QPrinterInfo::availablePrinters();
qDebug() << "len = " << plist.length(); // len comes back zero

QPrinter printer;
printer.setPrinterName("DYMO LabelWriter 450");
qDebug() << "printer valid? " << printer.isValid(); // comes back false


I have another application that uses the same code and it reports 7 printers and prints to the Dymo just fine.
Any idea what I am missing here?

derrickbj
23rd November 2013, 03:10
What happens if you use a PrintDialog instead? Something like


QPrintDialog dialog(printer, this);
if (dialog.exec() == QDialog::Rejected) {
return;
} Does it show a list of printers attached to the computer?

K4ELO
23rd November 2013, 16:42
QPrintDialog returns: QPrintDialog: Cannot be used on non-native printers
Because no printers are found.

yagabey
24th December 2013, 07:40
I also have the same problem. On my development machine(Win7 64 Bit, Qt 5.2 mingw) it works. But when i deploy the application to another computer i get the warning:

QPrintDialog: Cannot be used on non-native printers

I tried it with WinXP on virtualbox, again the problem exists. plugins\printsupport\windowsprintersupport.dll and platform\qwindows.dll exists in binary folder.

Any idea ?

K4ELO
24th December 2013, 16:16
Sorry Yagabey, no idea. Also running under Win 7/64. I have 2 applications. Both use the same code. It works on one but not the other. The one that does not work returns a list of zero printers from QList <QPrinterInfo> plist = QPrinterInfo::availablePrinters();
And print dialog gives me the same error message that you get.

Ritchie
18th February 2014, 13:35
Hi guys! I had the same problem and the reason was I put the wrong "windowsprintersupport.dll" in "plugins\printsupport\" dir. There were two different dll files in my Qt dir. You should take the right one.

hazad
15th March 2015, 18:30
QPrintDialog can't be used with pdfs on Windows because it is a native print dialog and has no knowledge of Qt's PDF printer.

psb2519
15th April 2015, 09:15
I have the same problem...
I changed the line
printer.setOutputFileName("Filename.pdf");
to
printer.setOutputFileName("Filename");
and the printdialog worked.
I made sure the print to file was not ticked...and whalla...(ozzie slang for great it worked)
a print of what I wanted worked.

Thanks for the Help to all