Re: terminate called after throwing an instance of 'Glib::FileError'

Thank you guys for the responses!

I am not sure why this happened but when I clicked on the executable file the program ran. However, when I started it using Terminal, the program got error again. Anyway I think I just started it directly then...

BTW, does anyone know how to create a Gtk::Button that contains Stock image. In other words, do you know how to create a GtkStockButton without label?

On Sun, Jun 19, 2011 at 12:31 PM, Bastien Durel <bastien durel org> wrote:
Le dimanche 19 juin 2011 à 13:31 +0200, Kjell Ahlstedt a écrit :
> Gdk::Pixbuf::create_from_file("now-playing.png") searches for the file
> in the current directory, which is the directory from where the program
> was started. That's not necessarily the directory where the program's
> executable file is stored.
> You need to call a function that tells you where your executable is
> stored (search path, not just filename). Unfortunately I don't know
> which function is appropriate. Perhaps someone else knows?

You may play with these functions :

You may see in argv[0] if the program was launched with a path
(./debug/foo), and then use build_path & others to construct your image
path name. Using find_program_in_path will help you if the user lauched
it from nowhere because it's in the path.
Using get_(system|user)_data_dirs may help if the program is installed.

And using Glib::File::query_exists() before calling create_from_file
will prevent throwing an exception (useful to search your file through
directories ;))

A linux-only application may read /proc/PID/exe, but it's not portable,
and you may use gtk for this ;)


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