How to discover no of printers available in yourr network?
Hey Guys !!
i am new to qt4.7.2 and i got task to discover no of printers available in your network?
I have read qt docs and got qprinterinfo class having availableprinter() function but can anyone give me idea about how to use it ? i am working on unix platform.
Thanks...
regards ,
Sumit
Re: How to discover no of printers available in yourr network?
Quote:
can anyone give me idea about how to use it ?
You just call it!
What is there to explain?
If you know how to call a function, you know how to use it!
Re: How to discover no of printers available in yourr network?
hi wiseguy,
I have searched for programs based on printer but nobody has explain these things properly.I went to Qt
website but no examples are there.If you have any examples please let us know..
regards,
Sumit
Re: How to discover no of printers available in yourr network?
(my username is high_flyer)
Again - example for what?
you have found the correct function to solve your problem, just use it.
What is your question?
Re: How to discover no of printers available in yourr network?
Hi high_flyer,
I have written code to show one of the available printer name ,I have used QLineText to show printer name
but getting error in following part of code:
Code:
void qprint::give_name_of_printer()
{
QPrinterInfo PrinterInfo;
//line no 33
QList<QPrinterInfo> pinfo;
//line 34
pinfo= PrinterInfo.availablePrinters(); // transferring QList into temp list pinfo
str=pinfo.value(1).printerName();//value function will return Qprinterinfo object at 2nd location & that object
// is used get printer name & stored in CString object
Name_edit->setText(str);//This is used to set text to printer name
}
I am getting error as incomplete type and cannot be defined 'class QList<QPrinterInfo>' at line no 33
can you please help me out...
Thanks
Regards,
Sumit
Re: How to discover no of printers available in yourr network?
Did you remember to #include the proper header file?
Re: How to discover no of printers available in yourr network?
You code is fine, it will work, may be you missed to include <QList> file, just add it and any other file which is required, you should have it running.
Tip:
when you read the printer name, make sure the list contains the printers on the first hand, else your program will crash
Code:
...
str=pinfo.value(1).printerName(); // this is not suggersted;
...
if(pinfo.count() > n)
str=pinfo.value(n).printerName();// get nth printer name
...
remember to post the code in code tags
Re: How to discover no of printers available in yourr network?
Re: How to discover no of printers available in yourr network?
You also don't need to create an instance of QPrinterInfo (line 4) in order to use the static method QPrinterInfo::availablePrinters().
Re: How to discover no of printers available in yourr network?
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:
Code:
//**********************************
#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();
}
//***************************
print.cpp:
Code:
//*****************************
#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);
}
//***********************************
print.h
Code:
//***********************************
#include <QtGui>
class QPrinterInfo;
class CString;
#include<QList>;
{
Q_OBJECT
QList<QPrinterInfo> info;
public:
qprint();
void give_no_of_printer();
};
//****************************
thanks
regards,
Sumit
Added after 4 minutes:
Quote:
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
Re: How to discover no of printers available in yourr network?
Quote:
if i dont create an instance of QPrinterInfo as per u how qt will call availablePrinters function.coz this function comes under QPrinterinfo
M I correct or not?
Plz guide me.
Qt does't do anything, its plain C++ which will call QPrinterInfo::availablePrinters(), as this is static call it need not have a instance to call (you can also call with instance if you have on)
refer http://www.cplusplus.com/doc/tutorial/classes2/ for Static members
Quote:
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 ..
Controls are already provided to enable users to choose from the printers available, including any configured network printers. Make sure your network printer (hosted on windows) is configured in unix.
Re: How to discover no of printers available in yourr network?
Quote:
Originally Posted by
Santosh Reddy
Qt does't do anything, its plain C++ which will call QPrinterInfo::availablePrinters(), as this is static call it need not have a instance to call (you can also call with instance if you have on)
refer
http://www.cplusplus.com/doc/tutorial/classes2/ for Static members
Controls are already provided to enable users to choose from the printers available, including any configured network printers. Make sure your network printer (hosted on windows) is configured in unix.
thanks alot buddy.
Re: How to discover no of printers available in yourr network?
Edit your post to use [code][/code] tags around your code before someone loses their eyesight trying to read that mess.
Quote:
hi
if i dont create an instance of QPrinterInfo as per u how qt will call availablePrinters function.coz this function comes under QPrinterinfo
M I correct or not?
Plz guide me.
You can call it directly. As a static member method it does not need an object instance to function.
Code:
QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
If you use the standard Qt print dialogs then this is done for you anyway.
Re: How to discover no of printers available in yourr network?
Quote:
Originally Posted by
ChrisW67
Edit your post to use [code][/code] tags around your code before someone loses their eyesight trying to read that mess.
You can call it directly. As a static member method it does not need an object instance to function.
Code:
QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
If you use the standard Qt print dialogs then this is done for you anyway.
Thanks buddy,
from next time onwords , I will remember what said ...n sorry for mess .
I got your point & I tried using QPrintDialog it works fine ..thanks
Discovery of printers in the network?
Hi Guys,
Is there any API in Qt which will communicate with my print server to discover all printer present in the network???
The function availablePrinters() is giving me locally configured printer details,But I want list of all printer present in the network on my machine..
Plz guide me..
Thank you
Regards,
Sumit
Re: Discovery of printers in the network?
You need to perform the process of service discovery. It differs based on the protocols the printers implement. You can try using zeroonf (http://doc.qt.nokia.com/qq/qq23-bonjour.html)
Bonjour service for printer
Hi guys,
Can you guys please provide some direction on how I can use Bonjour service in Qt app to discover printer devices on the dedicated printer network?
I have used http://doc.qt.nokia.com/qq/qq23-bonjour.html link but can't able to understand properly how to proceed...
can anyone give me good n simple example for this..
please give me somw guidence ..
Thank you
Regards,
Sumit
Re: Bonjour service for printer
Please stop multiposting!
What exactly are you having problems with?
Re: Bonjour service for printer
Quote:
Originally Posted by
wysota
Please stop multiposting!
What exactly are you having problems with?
Extreme apologies my friend ! i should not supposed create another thread for same problem ..sorry
i have already mention my problem in my previous post
regards,
sumit
Re: Bonjour service for printer
There are examples included in the link. If you do not understand the examples, which part are you having problems with? Saying "can't able to understand" is too vague.