signal printing to terminal
- From: Jamie Lahowetz <deadpickle gmail com>
- To: gtkmm-list <gtkmm-list gnome org>
- Subject: signal printing to terminal
- Date: Tue, 1 May 2012 15:59:59 -0500
This is probably a fairly easy question but Im very new to c++ and gtkmm
and am trying to connect a signal to a glade created entry. when return
is pressed the text is grabbed from the entry and displays in the
terminal... only nothing happens. A little help would be nice as to what
im doing wrong. Thank you.
main.cpp:
#include <gtkmm.h>
#include <iostream>
#include "terminal.h"
int main(int argc, char *argv[])
{
// required to start application methods
Gtk::Main kit(argc, argv);
Gtk::Window *mainwindow;
//Load the GtkBuilder file
Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create();
try
{
refBuilder->add_from_file("
hprcc.glade");
}
catch(const Glib::FileError& ex)
{
std::cerr << "FileError: " << ex.what() << std::endl;
return 1;
}
catch(const Glib::MarkupError& ex)
{
std::cerr << "MarkupError: " << ex.what() << std::endl;
return 1;
}
catch(const Gtk::BuilderError& ex)
{
std::cerr << "BuilderError: " << ex.what() << std::endl;
return 1;
}
// get the main window widget
refBuilder->get_widget("mainwindow", mainwindow);
// start the event loop
kit.run(*mainwindow);
return 0;
}
terminal.cpp:
#include "terminal.h"
#include <iostream>
using namespace std;
MainWindow::MainWindow(BaseObjectType* base_object,const Glib::RefPtr<Gtk::Builder>& glade_widget) : Gtk::Window(base_object)
{
// widgets from Glade
glade_widget->get_widget("stnidentry", stnidentry);
// Signals
stnidentry->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::get_stn_info));
}
MainWindow::~MainWindow()
{
}
void MainWindow::get_stn_info()
{
Glib::ustring stnid;
stnid = stnidentry->get_text();
std::cout << stnid << std::endl;
}
terminal.h:
#ifndef TERMINAL_H
#define TERMINAL_H
#include <gtkmm.h>
class MainWindow : public Gtk::Window
{
public:
MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& glade_widget);
virtual ~MainWindow();
protected:
// custom callbacks
void get_stn_info();
// widgets from Glade
Gtk::Entry* stnidentry;
};
#endif // TERMINAL_H
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]