Hi Guys,
Thanks alot for ur soln it really works.but m getting one problem ,when i put
int n as value it should show me printer's name to which m currently connected in the network.My printer
name is SJM_TESTER in windows. , but it shows me following values
for
n=0 printer
n=1 epr
n=2: ipr
n=3: pdf
n=4: null string
what must be problem ?How should I go ahead?M attaching source file below
m running my Qt on unix..
please help me.
main.cpp:
//**********************************
#include "print.h"
#include <QDesktopWidget>
#include <QApplication>
int main(int argc, char *argv[])
{
qprint window;
app.setFont(font);
//window.setWindowTitle("printer info");
window.showFullScreen();
//center(window);
return app.exec();
}
//***************************
//**********************************
#include "print.h"
#include <QDesktopWidget>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
qprint window;
QFont font("Arial");
app.setFont(font);
//window.setWindowTitle("printer info");
window.showFullScreen();
//center(window);
return app.exec();
}
//***************************
To copy to clipboard, switch view to plain text mode
print.cpp:
//*****************************
#include "print.h"
qprint::qprint()
{
grid->setSpacing(80);
Name
= new QLabel("printer name",
this);
grid->addWidget(Name, 0, 0, 1, 1);
grid->addWidget(Name_edit, 0, 1, 1, 1);
Name->setBuddy(Name_edit);
setLayout(grid);
give_no_of_printer();
}
void qprint::give_no_of_printer()
{ int n=5;
QPrinterInfo PrinterInfo;
info= PrinterInfo.availablePrinters();
if(info.count() > n)
str=info.value(n).printerName();
//defaultPrinter();
Name_edit->setText(str);
}
//***********************************
//*****************************
#include "print.h"
qprint::qprint()
{
sumit=new QPrinter(QPrinter::ScreenResolution);
grid = new QGridLayout(this);
grid->setSpacing(80);
Name= new QLabel("printer name", this);
grid->addWidget(Name, 0, 0, 1, 1);
Name_edit= new QLineEdit(this);
grid->addWidget(Name_edit, 0, 1, 1, 1);
Name->setBuddy(Name_edit);
setLayout(grid);
give_no_of_printer();
}
void qprint::give_no_of_printer()
{ int n=5;
QPrinterInfo PrinterInfo;
info= PrinterInfo.availablePrinters();
if(info.count() > n)
str=info.value(n).printerName();
//defaultPrinter();
Name_edit->setText(str);
}
//***********************************
To copy to clipboard, switch view to plain text mode
print.h
//***********************************
#include <QtGui>
class QPrinterInfo;
class CString;
#include<QList>;
{
Q_OBJECT
QList<QPrinterInfo> info;
public:
qprint();
void give_no_of_printer();
};
//****************************
//***********************************
#include <QtGui>
class QPrinterInfo;
class CString;
class QLabel;
class QLineEdit;
class QPrinter;
class QGridLayout;
#include<QList>;
class qprint : public QMainWindow
{
Q_OBJECT
QString str;
QList<QPrinterInfo> info;
QPrinter *sumit;
QLabel *Name;
QLineEdit *Name_edit;
QGridLayout *grid;
public:
qprint();
void give_no_of_printer();
};
//****************************
To copy to clipboard, switch view to plain text mode
thanks
regards,
Sumit
Added after 4 minutes:

Originally Posted by
ChrisW67
hi
if i dont create an instance of QPrinterInfo as per u how qt will call availablePrinters function.coz this function comes under QPrinterinfoM I correct or not?
Plz guide me.
hi guys,
I have used lpstat -a in unix and i got previously mention printrers .that means code my is working properly..
I would like to ask you if i create QPrintdialog's instance then, is that class directly adds available printers in the system to its dialog box's printer list or we have to write code for that ..
plz guide me..
regards,
Sumit
Bookmarks