Re: Problems enumerating printers



On Tue, 2008-12-30 at 00:09 +0100, Tor Krill wrote:
> Hi,
> 
> I have a bit of a newbie problem. Im trying to enumerate printers on a
> system. Doing so i get a lot off errors. Cut down version of code:
> 
> ----------8<----------------------------------------------------------
> #include <iostream>
> #include <gtkmm.h>
> #include <gtkmm/main.h>
> 
> using namespace std;
> 
> static bool enumerate(const Glib::RefPtr<Gtk::Printer>& printer){
> 	
> 	cout << "Printer:"<<printer->property_name()<<endl;
> 	
> 	return false;
> }
> 
> 
> int main(int argc, char *argv[]) {
> 	Gtk::Main kit(argc, argv);
> 
> 	Gtk::enumerate_printers(sigc::ptr_fun(enumerate),true);
> 
> 	return 0;
> }
> ----------8<----------------------------------------------------------
> 
> Output when executing:
> 
> ----------8<----------------------------------------------------------
> tor sid:~/tests/cpp_enumerate$ ./enumtest 
> Printer:Print to File
> 
> (enumtest:30909): GLib-GObject-CRITICAL **: g_object_unref: assertion
> `G_IS_OBJECT (object)' failed
> Printer:QL-500
> Printer:tors
> 
> (enumtest:30909): GLib-GObject-CRITICAL **: g_object_unref: assertion
> `G_IS_OBJECT (object)' failed
> 
> (enumtest:30909): GLib-GObject-CRITICAL **: g_object_unref: assertion
> `G_IS_OBJECT (object)' failed
> ----------8<----------------------------------------------------------

This was a bug in gtkmm. I have fixed it in SVN (gtkmm-2-12, gtkmm-2-14
and trunk). Until that fix hits a tarball release you can use the C API
directly:

#include <gtk/gtkunixprint.h>

gboolean enumerate(GtkPrinter* printer_, gpointer data)
{
  Glib::RefPtr<Printer> printer(printer_, true);
  std::cout << printer->property_name() << std::endl;
}

gtk_enumerate_printers(enumerate, NULL, NULL, TRUE);

You'll also need to specify gtk+-unix-print-2.0 in pkg-config for this to work.

Armin



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]