PDA

View Full Version : Discovery of printers in the network?



surwassu
25th May 2011, 08:29
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

high_flyer
25th May 2011, 08:47
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!

surwassu
25th May 2011, 10:25
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

high_flyer
25th May 2011, 10:31
(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?

surwassu
25th May 2011, 13:26
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:


void qprint::give_name_of_printer()

{
QPrinterInfo PrinterInfo;
QPrinter *printer=new QPrinter(QPrinter::ScreenResolution);
//line no 33
QList<QPrinterInfo> pinfo;
//line 34
QString str;
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

wysota
25th May 2011, 13:42
Did you remember to #include the proper header file?

Santosh Reddy
25th May 2011, 13:47
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


...
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

surwassu
26th May 2011, 01:56
thanks alot........

ChrisW67
26th May 2011, 04:46
You also don't need to create an instance of QPrinterInfo (line 4) in order to use the static method QPrinterInfo::availablePrinters().

surwassu
26th May 2011, 05:29
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[])
{
QApplication app(argc, argv);

qprint window;
QFont font("Arial");
app.setFont(font);
//window.setWindowTitle("printer info");
window.showFullScreen();
//center(window);

return app.exec();
}

//***************************


print.cpp:

//*****************************

#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);

}

//***********************************

print.h

//***********************************
#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();

};
//****************************



thanks
regards,
Sumit

Added after 4 minutes:


You also don't need to create an instance of QPrinterInfo (line 4) in order to use the static method QPrinterInfo::availablePrinters().

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.


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

Santosh Reddy
26th May 2011, 05:43
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


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.

surwassu
26th May 2011, 05:50
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.

ChrisW67
26th May 2011, 06:02
Edit your post to use
tags around your code before someone loses their eyesight trying to read that mess.


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.


QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();


If you use the standard Qt print dialogs then this is done for you anyway.

surwassu
26th May 2011, 06:31
Edit your post to use
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.


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

surwassu
26th May 2011, 08:47
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

wysota
26th May 2011, 09:29
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)

surwassu
26th May 2011, 12:34
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

wysota
26th May 2011, 12:51
Please stop multiposting!

What exactly are you having problems with?

surwassu
26th May 2011, 17:00
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

squidge
26th May 2011, 17:28
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.

surwassu
27th May 2011, 05:45
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.

Hi ,
Good morning to all!

I have gone through this link http://doc.qt.nokia.com/qq/qq23-bonjour.html (topic:Storing a Bonjour Entry).

Can anybody tell me why they have use Q_DECLARE_METATYPE(BonjourRecord)?The explaination given by them is not understandable.

Also why they have use reply domain?what does it mean?what is use of that?

Please guide me.
Reagds,
Sumit

wysota
27th May 2011, 06:48
Can anybody tell me why they have use Q_DECLARE_METATYPE(BonjourRecord)?
Because it allows to store objects of BonjourRecord class into QVariant.


Also why they have use reply domain?what does it mean?what is use of that?
Read about how zeroconf works and you'll understand that.

surwassu
27th May 2011, 08:22
Because it allows to store objects of BonjourRecord class into QVariant.


Read about how zeroconf works and you'll understand that.

Hi Master,
I have gone through that code n downloaded source file it contails three folder .
Do you have any idea about how to should I proceed to execute it on unix ?
Thanks.
Regards,
Sumit

wysota
27th May 2011, 08:56
Come on. Read the readme file.

surwassu
27th May 2011, 08:58
Come on. Read the readme file.

Do you have any idea from where i can get QPrintDialog class's Source code?

wysota
27th May 2011, 09:10
Right along the source code of the rest of Qt. Look on the front page of this site.

surwassu
27th May 2011, 09:56
Do you have any idea from where i can get QPrintDialog class's Source code?

My dear friend
i have read that file but nothing is mention about how to run it..They mentioned following things

<Readme>These are provided with qmake project files which
can be used to configure and build the source code.</Readme>

I have run make command for fortuneserver it gives me error

<error >
In file included from bonjourserviceregister.cpp:29:
bonjourserviceregister.h:37: fatal error: dns_sd.h: No such file or directory
compilation terminated.
</error>

can u help me please.
regards,
Sumit

wysota
27th May 2011, 10:27
Did you even bother to try and understand what bonjour is, how it works and what is required to use it?