<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Simple Text Example</title> <link rel="stylesheet" type="text/css" href="style.css"> <meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> <link rel="home" href="index.html" title="Programming with gtkmm 3"> <link rel="up" href="chapter-combobox.html" title="Chapter 10. Combo Boxes"> <link rel="prev" href="combobox-example-full.html" title="Full Example"> <link rel="next" href="sec-comboboxentry.html" title="ComboBox with an Entry"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">Simple Text Example</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="combobox-example-full.html"><img src="icons/prev.png" alt="Prev"></a> </td> <th width="60%" align="center">Chapter 10. Combo Boxes</th> <td width="20%" align="right"> <a accesskey="n" href="sec-comboboxentry.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="sect1"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="combobox-example-simple"></a>Simple Text Example</h2></div></div></div> <div class="figure"> <a name="figure-combobox-text"></a><p class="title"><b>Figure 10.2. ComboBoxText</b></p> <div class="figure-contents"><div class="screenshot"><div><img src="figures/combobox_text.png" alt="ComboBoxText"></div></div></div> </div> <br class="figure-break"><p><a class="ulink" href="http://git.gnome.org/browse/gtkmm-documentation/tree/examples/book/combobox/text?h=gtkmm-3-24" target="_top">Source Code</a></p> <p>File: <code class="filename">examplewindow.h</code> (For use with gtkmm 3, not gtkmm 2) </p> <pre class="programlisting"> #ifndef GTKMM_EXAMPLEWINDOW_H #define GTKMM_EXAMPLEWINDOW_H #include <gtkmm/window.h> #include <gtkmm/comboboxtext.h> class ExampleWindow : public Gtk::Window { public: ExampleWindow(); virtual ~ExampleWindow(); protected: //Signal handlers: void on_combo_changed(); //Child widgets: Gtk::ComboBoxText m_Combo; }; #endif //GTKMM_EXAMPLEWINDOW_H </pre> <p>File: <code class="filename">main.cc</code> (For use with gtkmm 3, not gtkmm 2) </p> <pre class="programlisting"> #include "examplewindow.h" #include <gtkmm/application.h> int main(int argc, char *argv[]) { auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example"); ExampleWindow window; //Shows the window and returns when it is closed. return app->run(window); } </pre> <p>File: <code class="filename">examplewindow.cc</code> (For use with gtkmm 3, not gtkmm 2) </p> <pre class="programlisting"> #include "examplewindow.h" #include <iostream> ExampleWindow::ExampleWindow() { set_title("ComboBoxText example"); //Fill the combo: m_Combo.append("something"); m_Combo.append("something else"); m_Combo.append("something or other"); m_Combo.set_active(1); add(m_Combo); //Connect signal handler: m_Combo.signal_changed().connect(sigc::mem_fun(*this, &ExampleWindow::on_combo_changed) ); show_all_children(); } ExampleWindow::~ExampleWindow() { } void ExampleWindow::on_combo_changed() { Glib::ustring text = m_Combo.get_active_text(); if(!(text.empty())) std::cout << "Combo changed: " << text << std::endl; } </pre> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="combobox-example-full.html"><img src="icons/prev.png" alt="Prev"></a> </td> <td width="20%" align="center"><a accesskey="u" href="chapter-combobox.html"><img src="icons/up.png" alt="Up"></a></td> <td width="40%" align="right"> <a accesskey="n" href="sec-comboboxentry.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">Full Example </td> <td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td> <td width="40%" align="right" valign="top"> ComboBox with an Entry</td> </tr> </table> </div> </body> </html>