gtkmm: Gtk::Builder Class Reference

Build an interface from an XML UI definition description. More...

#include <gtkmm/builder.h>

Inheritance diagram for Gtk::Builder:

Public Member Functions

 Builder (Builder&& src) noexcept
 
Builderoperator= (Builder&& src) noexcept
 
 ~Builder () noexceptoverride
 
GtkBuilder* gobj ()
 Provides access to the underlying C GObject. More...

 
const GtkBuilder* gobj () const
 Provides access to the underlying C GObject. More...

 
GtkBuilder* gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...

 
bool add_from_file (const std::string& filename)
 Parses a file containing a GtkBuilder UI definition, and merges it with the current contents of the builder. More...

 
bool add_from_file (const std::string& filename, const char* object_id)
 Parses a file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder. More...

 
bool add_from_file (const std::string& filename, const Glib::ustring& object_id)
 Parses a file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder. More...

 
bool add_from_file (const std::string& filename, const std::vector< Glib::ustring >& object_ids)
 Parses a file containing a [GtkBuilder UI definition][BUILDER-UI] building only the requested objects and merges them with the current contents of builder. More...

 
bool add_from_resource (const std::string& resource_path)
 Parses a resource file containing a GtkBuilder UI definition, and merges it with the current contents of the builder. More...

 
bool add_from_resource (const std::string& resource_path, const char* object_id)
 Parses a resource file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder. More...

 
bool add_from_resource (const std::string& resource_path, const Glib::ustring& object_id)
 Parses a resource file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder. More...

 
bool add_from_resource (const std::string& resource_path, const std::vector< Glib::ustring >& object_ids)
 Parses a resource file containing a [GtkBuilder UI definition][BUILDER-UI] building only the requested objects and merges them with the current contents of builder. More...

 
bool add_from_string (const Glib::ustring& buffer)
 Parses a string containing a GtkBuilder UI definition and merges it with the current contents of the builder. More...

 
bool add_from_string (const Glib::ustring& buffer, const char* object_id)
 Parses a string containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder. More...

 
bool add_from_string (const Glib::ustring& buffer, const Glib::ustring& object_id)
 Parses a string containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder. More...

 
bool add_from_string (const Glib::ustring& buffer, const std::vector< Glib::ustring >& object_ids)
 Parses a string containing a GtkBuilder UI definition, building only the requested objects, and merges it with the current contents of the builder. More...

 
bool add_from_string (const char* buffer, gsize length)
 Parses a string containing a GtkBuilder UI definition and merges it with the current contents of the builder. More...

 
void expose_object (const Glib::ustring& name, const Glib::RefPtr< Glib::Object >& object)
 Add object to the builder object pool so it can be referenced just like any other object built by builder. More...

 
void expose_widget (const Glib::ustring& name, Widget& widget)
 Add widget to the builder object pool so it can be referenced just like any other object built by builder. More...

 
Glib::RefPtr< Glib::Objectget_object (const Glib::ustring& name)
 Gets the object named name. More...

 
Glib::RefPtr< const Glib::Objectget_object (const Glib::ustring& name) const
 Gets the object named name. More...

 
template<class T_Widget >
void get_widget (const Glib::ustring& name, T_Widget*& widget)
 Gets a widget from the Builder file. More...

 
template<class T_Widget >
void get_widget (const Glib::ustring& name, const T_Widget*& widget) const
 See the non-const version. More...

 
template<typename T_Widget , typename... Args>
void get_widget_derived (const Glib::ustring& name, T_Widget*& widget, Args&&...args)
 Gets a widget whose details are specified in the GtkBuilder file, but which is implemented by your own derived class. More...

 
template<typename T_Widget , typename... Args>
void get_widget_derived (const Glib::ustring& name, const T_Widget*& widget, Args&&...args) const
 See the non-const version. More...

 
std::vector< Glib::RefPtr< Glib::Object > > get_objects ()
 Gets all objects that have been constructed by the Gtk::Builder. More...

 
std::vector< Glib::RefPtr< const Glib::Object > > get_objects () const
 Gets all objects that have been constructed by the Gtk::Builder. More...

 
void set_translation_domain (const Glib::ustring& domain)
 Sets the translation domain of builder. More...

 
Glib::ustring get_translation_domain () const
 Gets the translation domain of builder. More...

 
void set_application (const Glib::RefPtr< Application >& application)
 Sets the application associated with builder. More...

 
Glib::RefPtr< Applicationget_application ()
 Gets the Gtk::Application associated with the builder. More...

 
Glib::RefPtr< const Applicationget_application () const
 Gets the Gtk::Application associated with the builder. More...

 
Glib::PropertyProxy< Glib::ustringproperty_translation_domain ()
 The translation domain used when translating property values that have been marked as translatable in interface descriptions. More...

 
Glib::PropertyProxy_ReadOnly< Glib::ustringproperty_translation_domain () const
 The translation domain used when translating property values that have been marked as translatable in interface descriptions. More...

 
- Public Member Functions inherited from Glib::Object
 Object (const Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&src) noexcept
 
Objectoperator= (Object &&src) noexcept
 
void * get_data (const QueryQuark &key)
 
void set_data (const Quark &key, void *data)
 
void set_data (const Quark &key, void *data, DestroyNotify notify)
 
void remove_data (const QueryQuark &quark)
 
void * steal_data (const QueryQuark &quark)
 
Glib::RefPtr< Glib::Objectwrap (GObject *object, bool take_copy=false)
 
- Public Member Functions inherited from Glib::ObjectBase
 ObjectBase (const ObjectBase &)=delete
 
ObjectBaseoperator= (const ObjectBase &)=delete
 
void set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
 
void get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
 
void set_property (const Glib::ustring &property_name, const PropertyType &value)
 
void get_property (const Glib::ustring &property_name, PropertyType &value) const
 
PropertyType get_property (const Glib::ustring &property_name) const
 
sigc::connection connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
 
sigc::connection connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
 
void freeze_notify ()
 
void thaw_notify ()
 
virtual void reference () const
 
virtual void unreference () const
 
GObject * gobj ()
 
const GObject * gobj () const
 
GObject * gobj_copy () const
 
- Public Member Functions inherited from sigc::trackable
 trackable () noexcept
 
 trackable (const trackable &src) noexcept
 
 trackable (trackable &&src)
 
 ~trackable ()
 
void add_destroy_notify_callback (void *data, func_destroy_notify func) const
 
void notify_callbacks ()
 
trackableoperator= (const trackable &src)
 
trackableoperator= (trackable &&src)
 
void remove_destroy_notify_callback (void *data) const
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...

 
static Glib::RefPtr< Buildercreate ()
 Creates a new builder object. More...

 
static Glib::RefPtr< Buildercreate_from_file (const std::string& filename)
 Parses a file containing a GtkBuilder UI definition. More...

 
static Glib::RefPtr< Buildercreate_from_file (const std::string& filename, const Glib::ustring& object_id)
 Parses a file containing a GtkBuilder UI definition, building only the requested object. More...

 
static Glib::RefPtr< Buildercreate_from_file (const std::string& filename, const char* object_id)
 Parses a file containing a GtkBuilder UI definition, building only the requested object. More...

 
static Glib::RefPtr< Buildercreate_from_file (const std::string& filename, const std::vector< Glib::ustring >& object_ids)
 Parses a file containing a GtkBuilder UI definition, building only the requested objects. More...

 
static Glib::RefPtr< Buildercreate_from_resource (const std::string& resource_path)
 Parses a resource file containing a GtkBuilder UI definition. More...

 
static Glib::RefPtr< Buildercreate_from_resource (const std::string& resource_path, const Glib::ustring& object_id)
 Parses a resource file containing a GtkBuilder UI definition, building only the requested object. More...

 
static Glib::RefPtr< Buildercreate_from_resource (const std::string& resource_path, const char* object_id)
 Parses a resource file containing a GtkBuilder UI definition, building only the requested object. More...

 
static Glib::RefPtr< Buildercreate_from_resource (const std::string& resource_path, const std::vector< Glib::ustring >& object_ids)
 Parses a resource file containing a GtkBuilder UI definition, building only the requested objects. More...

 
static Glib::RefPtr< Buildercreate_from_string (const Glib::ustring& buffer)
 Parses a string containing a GtkBuilder UI definition. More...

 
static Glib::RefPtr< Buildercreate_from_string (const Glib::ustring& buffer, const char* object_id)
 Parses a string containing a GtkBuilder UI definition building only the requested object. More...

 
static Glib::RefPtr< Buildercreate_from_string (const Glib::ustring& buffer, const Glib::ustring& object_id)
 Parses a string containing a GtkBuilder UI definition building only the requested object. More...

 
static Glib::RefPtr< Buildercreate_from_string (const Glib::ustring& buffer, const std::vector< Glib::ustring >& object_ids)
 Parses a string containing a GtkBuilder UI definition building only the requested objects. More...

 

Protected Member Functions

 Builder ()
 
Gtk::Widgetget_widget_checked (const Glib::ustring& name, GType type)
 
GtkWidget* get_cwidget (const Glib::ustring& name)
 
- Protected Member Functions inherited from Glib::Object
 Object ()
 
 Object (const Glib::ConstructParams &construct_params)
 
 Object (GObject *castitem)
 
 ~Object () noexceptoverride
 
- Protected Member Functions inherited from Glib::ObjectBase
 ObjectBase ()
 
 ObjectBase (const char *custom_type_name)
 
 ObjectBase (const std::type_info &custom_type_info)
 
 ObjectBase (ObjectBase &&src) noexcept
 
ObjectBaseoperator= (ObjectBase &&src) noexcept
 
virtual ~ObjectBase () noexcept=0
 
void initialize (GObject *castitem)
 
void initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gtk::Builderwrap (GtkBuilder* object, bool take_copy=false)
 A Glib::wrap() method for this object. More...

 

Additional Inherited Members

- Public Types inherited from Glib::Object
typedef void(*)(gpointer data DestroyNotify)
 
- Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify func_destroy_notify
 

Detailed Description

Build an interface from an XML UI definition description.

This object represents an `instantiation' of an UI definition description. When one of these objects is created, the XML file is read, and the user interface is created. The Gtk::Builder object then provides an interface for accessing the widgets in the user interface by the names assigned to them inside the UI description.

A Gtk::Builder holds a reference to all objects that it has constructed and drops these references when it is deleted. This deletion can cause the destruction of non-widget objects or widgets which are not contained in a toplevel window. For toplevel windows constructed by a builder, it is the responsibility of the user to get them with get_widget() or get_widget_derived() and delete them to get rid of them and all the widgets they contain.

The methods get_widget() and get_widget_derived() can be used to access the widgets in the interface by the names assigned to them inside the UI description. Toplevel windows returned by these methods will stay around until the user explicitly deletes them. Other widgets will either be part of a larger hierarchy constructed by the builder (in which case you should not have to worry about their lifecycle), or without a parent, in which case they have to be added to some container before the builder is deleted to make use of them. Non-widget objects need to be fetched with get_object() or get_objects() to keep them beyond the lifespan of the builder.

Since gtkmm 2.12:

Constructor & Destructor Documentation

Gtk::Builder::Builder ( Builder&&  src)
noexcept
Gtk::Builder::~Builder ( )
overridenoexcept
Gtk::Builder::Builder ( )
protected

Member Function Documentation

bool Gtk::Builder::add_from_file ( const std::string filename)

Parses a file containing a GtkBuilder UI definition, and merges it with the current contents of the builder.

Parameters
filenameThe file to parse.
Returns
true on success or false if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Glib::MarkupError
Since gtkmm 2.14:
bool Gtk::Builder::add_from_file ( const std::string filename,
const char *  object_id 
)

Parses a file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters
filenameThe file to parse.
object_idThe object to build.
Returns
true on success or false if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Glib::MarkupError
Since gtkmm 2.16:
bool Gtk::Builder::add_from_file ( const std::string filename,
const Glib::ustring object_id 
)

Parses a file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters
filenameThe file to parse.
object_idThe object to build.
Returns
true on success or false if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Glib::MarkupError
Since gtkmm 2.14:
bool Gtk::Builder::add_from_file ( const std::string filename,
const std::vector< Glib::ustring > &  object_ids 
)

Parses a file containing a [GtkBuilder UI definition][BUILDER-UI] building only the requested objects and merges them with the current contents of builder.

Upon errors 0 will be returned and error will be assigned a Error from the Gtk::BUILDER_ERROR, MARKUP_ERROR or FILE_ERROR domain.

If you are adding an object that depends on an object that is not its child (for instance a Gtk::TreeView that depends on its Gtk::TreeModel), you have to explicitly list all of them in object_ids.

Since gtkmm 2.14:
Parameters
filenameThe name of the file to parse.
object_idsNul-terminated array of objects to build.
Returns
A positive value on success, 0 if an error occurred.
bool Gtk::Builder::add_from_resource ( const std::string resource_path)

Parses a resource file containing a GtkBuilder UI definition, and merges it with the current contents of the builder.

Parameters
resource_pathThe path of the resource file to parse.
Returns
true on success or false if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Gio::ResourceError
Since gtkmm 3.6:
bool Gtk::Builder::add_from_resource ( const std::string resource_path,
const char *  object_id 
)

Parses a resource file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters
resource_pathThe path of the resource file to parse.
object_idThe object to build.
Returns
true on success or false if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Gio::ResourceError
Since gtkmm 3.6:
bool Gtk::Builder::add_from_resource ( const std::string resource_path,
const Glib::ustring object_id 
)

Parses a resource file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters
resource_pathThe path of the resource file to parse.
object_idThe object to build.
Returns
true on success or false if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Gio::ResourceError
Since gtkmm 3.6:
bool Gtk::Builder::add_from_resource ( const std::string resource_path,
const std::vector< Glib::ustring > &  object_ids 
)

Parses a resource file containing a [GtkBuilder UI definition][BUILDER-UI] building only the requested objects and merges them with the current contents of builder.

Upon errors 0 will be returned and error will be assigned a Error from the Gtk::BUILDER_ERROR, MARKUP_ERROR or RESOURCE_ERROR domain.

If you are adding an object that depends on an object that is not its child (for instance a Gtk::TreeView that depends on its Gtk::TreeModel), you have to explicitly list all of them in object_ids.

Since gtkmm 3.4:
Parameters
resource_pathThe path of the resource file to parse.
object_idsNul-terminated array of objects to build.
Returns
A positive value on success, 0 if an error occurred.
bool Gtk::Builder::add_from_string ( const Glib::ustring buffer)

Parses a string containing a GtkBuilder UI definition and merges it with the current contents of the builder.

Parameters
bufferThe string to parse.
Returns
true on success or false if an error occurred.
Exceptions
BuilderError,Glib::MarkupError
Since gtkmm 2.12:
bool Gtk::Builder::add_from_string ( const Glib::ustring buffer,
const char *  object_id 
)

Parses a string containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

Parameters
bufferThe string to parse.
object_idThe object to build.
Returns
true on success or false if an error occurred.
Exceptions
BuilderError,Glib::MarkupError
Since gtkmm 2.16:
bool Gtk::Builder::add_from_string ( const Glib::ustring buffer,
const Glib::ustring object_id 
)

Parses a string containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

Parameters
bufferThe string to parse.
object_idThe object to build.
Returns
true on success or false if an error occurred.
Exceptions
BuilderError,Glib::MarkupError
Since gtkmm 2.14:
bool Gtk::Builder::add_from_string ( const Glib::ustring buffer,
const std::vector< Glib::ustring > &  object_ids 
)

Parses a string containing a GtkBuilder UI definition, building only the requested objects, and merges it with the current contents of the builder.

Parameters
bufferThe string to parse.
object_idsThe objects to build.
Returns
true on success or false if an error occurred.
Exceptions
BuilderError,Glib::MarkupError
Since gtkmm 2.14:
bool Gtk::Builder::add_from_string ( const char *  buffer,
gsize  length 
)

Parses a string containing a GtkBuilder UI definition and merges it with the current contents of the builder.

Parameters
bufferThe string to parse.
lengthThe length of buffer (may be -1 if buffer is nul-terminated).
Returns
true on success or false if an error occurred.
Exceptions
BuilderError,Glib::MarkupError
Since gtkmm 2.12:
static Glib::RefPtr<Builder> Gtk::Builder::create ( )
static

Creates a new builder object.

static Glib::RefPtr<Builder> Gtk::Builder::create_from_file ( const std::string filename)
static

Parses a file containing a GtkBuilder UI definition.

Parameters
filenamethe name of the file to parse.
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Glib::FileError
Since gtkmm 2.12:
static Glib::RefPtr<Builder> Gtk::Builder::create_from_file ( const std::string filename,
const Glib::ustring object_id 
)
static

Parses a file containing a GtkBuilder UI definition, building only the requested object.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters
filenamethe name of the file to parse.
object_idThe object to build.
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Glib::FileError
Since gtkmm 2.14:
static Glib::RefPtr<Builder> Gtk::Builder::create_from_file ( const std::string filename,
const char *  object_id 
)
static

Parses a file containing a GtkBuilder UI definition, building only the requested object.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters
filenamethe name of the file to parse.
object_idThe object to build.
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Glib::FileError
Since gtkmm 2.16:
static Glib::RefPtr<Builder> Gtk::Builder::create_from_file ( const std::string filename,
const std::vector< Glib::ustring > &  object_ids 
)
static

Parses a file containing a GtkBuilder UI definition, building only the requested objects.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters
filenamethe name of the file to parse.
object_idsThe objects to build.
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Glib::FileError
Since gtkmm 2.14:
static Glib::RefPtr<Builder> Gtk::Builder::create_from_resource ( const std::string resource_path)
static

Parses a resource file containing a GtkBuilder UI definition.

Parameters
resource_pathThe path of the resource file to parse.
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Gio::ResourceError
Since gtkmm 3.6:
static Glib::RefPtr<Builder> Gtk::Builder::create_from_resource ( const std::string resource_path,
const Glib::ustring object_id 
)
static

Parses a resource file containing a GtkBuilder UI definition, building only the requested object.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters
resource_pathThe path of the resource file to parse.
object_idThe object to build.
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Gio::ResourceError
Since gtkmm 3.6:
static Glib::RefPtr<Builder> Gtk::Builder::create_from_resource ( const std::string resource_path,
const char *  object_id 
)
static

Parses a resource file containing a GtkBuilder UI definition, building only the requested object.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters
resource_pathThe path of the resource file to parse.
object_idThe object to build.
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Gio::ResourceError
Since gtkmm 3.6:
static Glib::RefPtr<Builder> Gtk::Builder::create_from_resource ( const std::string resource_path,
const std::vector< Glib::ustring > &  object_ids 
)
static

Parses a resource file containing a GtkBuilder UI definition, building only the requested objects.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters
resource_pathThe path of the resource file to parse.
object_idsThe objects to build.
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError,Gio::ResourceError
Since gtkmm 3.6:
static Glib::RefPtr<Builder> Gtk::Builder::create_from_string ( const Glib::ustring buffer)
static

Parses a string containing a GtkBuilder UI definition.

Parameters
bufferthe string to parse
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError
Since gtkmm 2.12:
static Glib::RefPtr<Builder> Gtk::Builder::create_from_string ( const Glib::ustring buffer,
const char *  object_id 
)
static

Parses a string containing a GtkBuilder UI definition building only the requested object.

Parameters
bufferThe string to parse.
object_idThe object to build.
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError
Since gtkmm 2.16:
static Glib::RefPtr<Builder> Gtk::Builder::create_from_string ( const Glib::ustring buffer,
const Glib::ustring object_id 
)
static

Parses a string containing a GtkBuilder UI definition building only the requested object.

Parameters
bufferThe string to parse.
object_idThe object to build.
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError
Since gtkmm 2.14:
static Glib::RefPtr<Builder> Gtk::Builder::create_from_string ( const Glib::ustring buffer,
const std::vector< Glib::ustring > &  object_ids 
)
static

Parses a string containing a GtkBuilder UI definition building only the requested objects.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters
bufferthe string to parse
object_idsThe objects to build.
Returns
A new Builder object, or a null pointer if an error occurred.
Exceptions
BuilderError,Glib::MarkupError
Since gtkmm 2.14:
void Gtk::Builder::expose_object ( const Glib::ustring name,
const Glib::RefPtr< Glib::Object > &  object 
)

Add object to the builder object pool so it can be referenced just like any other object built by builder.

Since gtkmm 3.8:
Parameters
nameThe name of the object exposed to the builder.
objectThe object to expose.
void Gtk::Builder::expose_widget ( const Glib::ustring name,
Widget widget 
)

Add widget to the builder object pool so it can be referenced just like any other object built by builder.

Since gtkmm 3.12:
Parameters
nameThe name of the widget exposed to the builder.
widgetThe widget to expose.
Glib::RefPtr<Application> Gtk::Builder::get_application ( )

Gets the Gtk::Application associated with the builder.

The Gtk::Application is used for creating action proxies as requested from XML that the builder is loading.

By default, the builder uses the default application: the one from Glib::application_get_default(). If you want to use another application for constructing proxies, use set_application().

Since gtkmm 3.10:
Returns
The application being used by the builder, or nullptr.
Glib::RefPtr<const Application> Gtk::Builder::get_application ( ) const

Gets the Gtk::Application associated with the builder.

The Gtk::Application is used for creating action proxies as requested from XML that the builder is loading.

By default, the builder uses the default application: the one from Glib::application_get_default(). If you want to use another application for constructing proxies, use set_application().

Since gtkmm 3.10:
Returns
The application being used by the builder, or nullptr.
GtkWidget* Gtk::Builder::get_cwidget ( const Glib::ustring name)
protected
Glib::RefPtr<Glib::Object> Gtk::Builder::get_object ( const Glib::ustring name)

Gets the object named name.

Since gtkmm 2.12:
Parameters
nameName of object to get.
Returns
The object named name or nullptr if it could not be found in the object tree.
Glib::RefPtr<const Glib::Object> Gtk::Builder::get_object ( const Glib::ustring name) const

Gets the object named name.

Since gtkmm 3.8:
Parameters
nameName of object to get.
Returns
The object named name or nullptr if it could not be found in the object tree.
std::vector<Glib::RefPtr<Glib::Object> > Gtk::Builder::get_objects ( )

Gets all objects that have been constructed by the Gtk::Builder.

Since gtkmm 3.8:
Returns
A vector containing all the objects constructed by the Gtk::Builder instance.
std::vector<Glib::RefPtr<const Glib::Object> > Gtk::Builder::get_objects ( ) const

Gets all objects that have been constructed by the Gtk::Builder.

Since gtkmm 3.8:
Returns
A vector containing all the objects constructed by the Gtk::Builder instance.
Glib::ustring Gtk::Builder::get_translation_domain ( ) const

Gets the translation domain of builder.

Since gtkmm 2.12:
Returns
The translation domain. This string is owned by the builder object and must not be modified or freed.
static GType Gtk::Builder::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

template <class T_Widget >
void Gtk::Builder::get_widget ( const Glib::ustring name,
T_Widget *&  widget 
)
inline

Gets a widget from the Builder file.

For instance:

Gtk::Grid* pGrid = nullptr;
refXml->get_widget("mygrid", pGrid);

This method prints a warning message to the console if the widget doesn't exist or has the wrong type, so you don't need to check that manually.

Note that you are responsible for deleting top-level widgets (windows and dialogs) instantiated by the Builder object. Other widgets are instantiated as managed so they will be deleted automatically if you add them to a container widget.

Parameters
nameThe name of the widget.
Return values
widgetA pointer to the widget, or nullptr on failure.
template <class T_Widget >
void Gtk::Builder::get_widget ( const Glib::ustring name,
const T_Widget *&  widget 
) const
inline

See the non-const version.

Since gtkmm 3.8:
Gtk::Widget* Gtk::Builder::get_widget_checked ( const Glib::ustring name,
GType  type 
)
protected
template <typename T_Widget , typename... Args>
void Gtk::Builder::get_widget_derived ( const Glib::ustring name,
T_Widget *&  widget,
Args &&...  args 
)
inline

Gets a widget whose details are specified in the GtkBuilder file, but which is implemented by your own derived class.

Your class must have a constructor like so:

MyDerivedDialog::MyDerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::Dialog(cobject) //Calls the base class constructor

or, with additional parameters, for example:

MyDerivedDialog::MyDerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder,
const Glib::ustring& msg, bool warning)
: Gtk::Dialog(cobject) //Calls the base class constructor

For instance:

MyDerivedDialog* pDialog1 = nullptr;
MyDerivedDialog* pDialog2 = nullptr;
refBuilder->get_widget_derived("mydialog1", pDialog1);
refBuilder->get_widget_derived("mydialog2", pDialog2, "A storm is imminent!", true);
Note
If get_widget_derived() is called more than once for the same widget (the same name), only the first call will call the widget's constructor. The following calls will return a pointer to the widget instance that was constructed by the first call.
Parameters
nameThe name of the widget.
argsAdditional arguments to pass to the constructor of the derived class.
Return values
widgetA pointer to the widget, or nullptr on failure.
template <typename T_Widget , typename... Args>
void Gtk::Builder::get_widget_derived ( const Glib::ustring name,
const T_Widget *&  widget,
Args &&...  args 
) const
inline

See the non-const version.

Since gtkmm 3.8:
GtkBuilder* Gtk::Builder::gobj ( )
inline

Provides access to the underlying C GObject.

const GtkBuilder* Gtk::Builder::gobj ( ) const
inline

Provides access to the underlying C GObject.

GtkBuilder* Gtk::Builder::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

Builder& Gtk::Builder::operator= ( Builder&&  src)
noexcept
Glib::PropertyProxy< Glib::ustring > Gtk::Builder::property_translation_domain ( )

The translation domain used when translating property values that have been marked as translatable in interface descriptions.

If the translation domain is nullptr, Gtk::Builder uses gettext(), otherwise Glib::dgettext().

Since gtkmm 2.12:
Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.
Glib::PropertyProxy_ReadOnly< Glib::ustring > Gtk::Builder::property_translation_domain ( ) const

The translation domain used when translating property values that have been marked as translatable in interface descriptions.

If the translation domain is nullptr, Gtk::Builder uses gettext(), otherwise Glib::dgettext().

Since gtkmm 2.12:
Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.
void Gtk::Builder::set_application ( const Glib::RefPtr< Application >&  application)

Sets the application associated with builder.

You only need this function if there is more than one Application in your process. application cannot be nullptr.

Since gtkmm 3.10:
Parameters
applicationA Gtk::Application.
void Gtk::Builder::set_translation_domain ( const Glib::ustring domain)

Sets the translation domain of builder.

See Gtk::Builder::property_translation_domain().

Since gtkmm 2.12:
Parameters
domainThe translation domain or nullptr.

Friends And Related Function Documentation

Glib::RefPtr< Gtk::Builder > wrap ( GtkBuilder *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.