Page 1 of 2 12 LastLast
Results 1 to 20 of 28

Thread: Discovery of printers in the network?

  1. #1
    Join Date
    May 2011
    Posts
    19
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to discover no of printers available in yourr network?

    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!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2011
    Posts
    19
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. The following user says thank you to high_flyer for this useful post:

    surwassu (26th May 2011)

  6. #5
    Join Date
    May 2011
    Posts
    19
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:

    Qt Code:
    1. void qprint::give_name_of_printer()
    2.  
    3. {
    4. QPrinterInfo PrinterInfo;
    5. QPrinter *printer=new QPrinter(QPrinter::ScreenResolution);
    6. //line no 33
    7. QList<QPrinterInfo> pinfo;
    8. //line 34
    9. QString str;
    10. pinfo= PrinterInfo.availablePrinters(); // transferring QList into temp list pinfo
    11. str=pinfo.value(1).printerName();//value function will return Qprinterinfo object at 2nd location & that object
    12. // is used get printer name & stored in CString object
    13. Name_edit->setText(str);//This is used to set text to printer name
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 





    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
    Last edited by high_flyer; 25th May 2011 at 15:19. Reason: code tags

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to discover no of printers available in yourr network?

    Did you remember to #include the proper header file?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    surwassu (26th May 2011)

  9. #7
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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
    Qt Code:
    1. ...
    2. str=pinfo.value(1).printerName(); // this is not suggersted;
    3. ...
    4. if(pinfo.count() > n)
    5. str=pinfo.value(n).printerName();// get nth printer name
    6. ...
    To copy to clipboard, switch view to plain text mode 
    remember to post the code in code tags

  10. The following user says thank you to Santosh Reddy for this useful post:

    surwassu (26th May 2011)

  11. #8
    Join Date
    May 2011
    Posts
    19
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to discover no of printers available in yourr network?

    thanks alot........

  12. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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().

  13. #10
    Join Date
    May 2011
    Posts
    19
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:
    Qt Code:
    1. //**********************************
    2.  
    3.  
    4. #include "print.h"
    5. #include <QDesktopWidget>
    6. #include <QApplication>
    7.  
    8.  
    9.  
    10.  
    11. int main(int argc, char *argv[])
    12. {
    13. QApplication app(argc, argv);
    14.  
    15. qprint window;
    16. QFont font("Arial");
    17. app.setFont(font);
    18. //window.setWindowTitle("printer info");
    19. window.showFullScreen();
    20. //center(window);
    21.  
    22. return app.exec();
    23. }
    24.  
    25. //***************************
    To copy to clipboard, switch view to plain text mode 


    print.cpp:
    Qt Code:
    1. //*****************************
    2.  
    3. #include "print.h"
    4.  
    5.  
    6.  
    7. qprint::qprint()
    8. {
    9. sumit=new QPrinter(QPrinter::ScreenResolution);
    10. grid = new QGridLayout(this);
    11. grid->setSpacing(80);
    12.  
    13. Name= new QLabel("printer name", this);
    14. grid->addWidget(Name, 0, 0, 1, 1);
    15.  
    16. Name_edit= new QLineEdit(this);
    17. grid->addWidget(Name_edit, 0, 1, 1, 1);
    18.  
    19. Name->setBuddy(Name_edit);
    20.  
    21.  
    22. setLayout(grid);
    23. give_no_of_printer();
    24. }
    25.  
    26.  
    27. void qprint::give_no_of_printer()
    28.  
    29. { int n=5;
    30. QPrinterInfo PrinterInfo;
    31. info= PrinterInfo.availablePrinters();
    32. if(info.count() > n)
    33. str=info.value(n).printerName();
    34. //defaultPrinter();
    35. Name_edit->setText(str);
    36.  
    37. }
    38.  
    39. //***********************************
    To copy to clipboard, switch view to plain text mode 

    print.h
    Qt Code:
    1. //***********************************
    2. #include <QtGui>
    3.  
    4.  
    5. class QPrinterInfo;
    6. class CString;
    7. class QLabel;
    8. class QLineEdit;
    9. class QPrinter;
    10. #include<QList>;
    11. class qprint : public QMainWindow
    12.  
    13.  
    14. {
    15.  
    16.  
    17.  
    18. Q_OBJECT
    19. QString str;
    20. QList<QPrinterInfo> info;
    21. QPrinter *sumit;
    22. QLabel *Name;
    23. QLineEdit *Name_edit;
    24. public:
    25. qprint();
    26. void give_no_of_printer();
    27.  
    28. };
    29. //****************************
    To copy to clipboard, switch view to plain text mode 



    thanks
    regards,
    Sumit


    Added after 4 minutes:


    Quote Originally Posted by ChrisW67 View Post
    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 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
    Last edited by wysota; 26th May 2011 at 09:26.

  14. #11
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to discover no of printers available in yourr network?

    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.

  15. The following user says thank you to Santosh Reddy for this useful post:

    surwassu (26th May 2011)

  16. #12
    Join Date
    May 2011
    Posts
    19
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to discover no of printers available in yourr network?

    Quote Originally Posted by Santosh Reddy View Post
    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.
    Last edited by wysota; 26th May 2011 at 09:28. Reason: reformatted to look better

  17. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

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

    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.
    Qt Code:
    1. QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
    To copy to clipboard, switch view to plain text mode 

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

  18. #14
    Join Date
    May 2011
    Posts
    19
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to discover no of printers available in yourr network?

    Quote Originally Posted by ChrisW67 View Post
    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.
    Qt Code:
    1. QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
    To copy to clipboard, switch view to plain text mode 

    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

  19. #15
    Join Date
    May 2011
    Posts
    19
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  20. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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)
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  21. #17
    Join Date
    May 2011
    Posts
    19
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  22. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Bonjour service for printer

    Please stop multiposting!

    What exactly are you having problems with?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  23. #19
    Join Date
    May 2011
    Posts
    19
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Bonjour service for printer

    Quote Originally Posted by wysota View Post
    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

  24. #20
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

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

Similar Threads

  1. QPrintDialog lists no printers
    By TMan in forum Qt Programming
    Replies: 6
    Last Post: 9th June 2009, 16:33
  2. Discovery correct Language on all OS
    By patrik08 in forum Qt Programming
    Replies: 5
    Last Post: 25th February 2007, 20:27
  3. QSqlField discovery auto_increment int value
    By patrik08 in forum Qt Programming
    Replies: 6
    Last Post: 3rd December 2006, 12:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.