GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 24, 2014 7:05 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: little help on basic gtkmm
PostPosted: Mon Jun 23, 2008 2:29 pm 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
This is my first attempt to use gtkmm, my skeletton code:
gwindow.hpp;
Code:
#ifndef GWINDOW_HPP
#include <gtkmm.h>

using Glib::ustring;

class GWindow : public Gtk::Window {
   public:
      GWindow(const ustring&);
      virtual ~GWindow();
};

#define GWINDOW_HPP
#endif

gwindow.cc
Code:
#include "gwindow.hpp"

GWindow::GWindow(const ustring &Title) {
   set_title(Title);
   set_border_width(10);
   resize(260, 110);
   
   Gtk::VBox panel;
   add(panel);
   
   Gtk::Label label1("Hola mundo");
   panel.pack_start(label1);
   
   Gtk::Button button("Bye");
   panel.pack_start(button);
   
   show_all();
   
}

GWindow::~GWindow() {
}

main.cc
Code:
#include <gtkmm/main.h>
#include "gwindow.hpp"

int main(int argc, char *argv[]) {
   Gtk::Main kit(argc, argv);
   GWindow gWindow("Hola mundo");
   Gtk::Main::run(gWindow);
   return 0;
}

The problem is that both label and button are not showed, any ideas?
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 2:59 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
are they shown if you explicitly call show()?
Code:
label1.show()
button.show()


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 6:54 pm 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
nop, the same :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 7:30 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
it appears to work if you put the variable declarations into the class declaration,
then do something like:
Code:
label.set_text("Hola Mundo!");
instead of
Code:
Gtk::Label label("Hola Mundo!");


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 10:46 pm 
Offline
Familiar Face

Joined: Sun Mar 09, 2008 2:23 am
Posts: 7
You need to declare any widget you are going to use in the header file that prototypes you window class. I assume that your have named it "gwindow.hpp"

So it should look something like this:
Code:
#ifndef GWINDOW_HPP
#include <gtkmm.h>

using Glib::ustring;

class GWindow : public Gtk::Window {
    public:
        GWindow(const ustring&);
        virtual ~GWindow();

    protected:
        Gtk::VBox panel;
        Gtk::Label label1;
        Gtk::Button button;
};

#define GWINDOW_HPP
#endif

and do the appropriate changes in "gwindow.cc"

I had the same problem and I solved it by accident. As far as I know the gtkmm documentation doesn't mention something like this. I just had a really good look at the tutorial-code!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group