Hi, i think that this example code will explain something :)
--------------------------
#include <gtkmm.h>
#include <iostream>
class MainWindow : public Gtk::Window
{
public:
MainWindow()
{
Glib::RefPtr<Gdk::Window> w = this->get_window();
if(!w)
std::cout << "w NULL" << std::endl;
show();
if(!w)
std::cout << "w still NULL" << std::endl;
}
void MainWindow::test()
{
Glib::RefPtr<Gdk::Window> w = this->get_window();
std::cout << "Test" << std::endl;
if(!w)
std::cout << "Test: w NULL" << std::endl;
}
~MainWindow(){}
};
int main(int argc, char** argv)
{
Gtk::Main kit(&argc, &argv);
MainWindow mainWindow;
mainWindow.test();
Gtk::Main::run(mainWindow);
exit(0);
}
-----------------------------------------
The exit on console is:
gooz Lain:~/Desktop/prueba$ ./ejemplo w NULL
w still NULL
Test
----------------------
I hope this helps. The window must be realized before you can use
get_window();
:)
El jue, 16-06-2005 a las 00:00 +0200, Andrea Spadaccini escribió:
> Hi everyone,
> I've got a problem with get_window().. gdb backtrace shows me that a
> segfault is caused by this function returning NULL from inside a member
> of my SubnetRenderer class, which is derived from Gtk::Drawable. here's
> the function that generates the problem:
>
> void SubnetRenderer::setStatus(int s) {
> Gdk::Cursor ar(Gdk::ARROW);
> Gdk::Cursor ch(Gdk::CROSSHAIR);
>
> // Non funge, non capisco perché..
> Glib::RefPtr<Gdk::Window> w = get_window();
> std::cout << "Sono qui! :)\n";
> Gdk::Color c("black");
> //gc->set_foreground(mainColor);
> if(w == NULL)
> std::cout << "E' NULL!!!\n";
> w->set_cursor(ar);
>
> switch(s) {
> case DEFAULT:
> sb_text = "Selezionare un oggetto per informazioni";
> break;
> case ADD_HOST:
> cleanSelections();
> sb_text = "Cliccare su un punto della mappa per aggiungere
> un host."; break;
> case ADD_ROUTER:
> cleanSelections();
> //get_window()->set_cursor(ch);
> sb_text = "Cliccare su un punto della mappa per aggiungere
> un router."; break;
> case SOMETHING_IS_SELECTED:
> sb_text = selected->getInfo();
> break;
> default:
> sb_text = "Questo stato è impossibile. Come direbbe
> Nunnari: \"Sei un PIIIIRLA\""; break;
> }
> status = s;
> }
>
> and here's the backtrace
>
> [...]
>
> (gdb) run
> Starting program: /home/andrea/Uni/Reti di Calcolatori/simulatore_reti/
> Sim Sono qui! :)
> E' NULL!!!
>
> Program received signal SIGSEGV, Segmentation fault.
> Gdk::Window::set_cursor(Gdk::Cursor const&) (this=0x0,
> cursor= 0xbffff110) at window.h:719
> 719 window.h: No such file or directory.
> in window.h
> (gdb) bt
> #0 Gdk::Window::set_cursor(Gdk::Cursor const&) (this=0x0,
> cursor= 0xbffff110) at window.h:719
> #1 0x08094f6d in SubnetRenderer::setStatus(int) (this=0xbffff4a0, s=0)
> at SubnetRenderer.cpp:178
> #2 0x08093f5a in SubnetRenderer (this=0xbffff4a0, xsize=700, ysize=600,
> dwb=0x0, ldwb=0x0) at SubnetRenderer.cpp:40
> #3 0x08099ee6 in TestWindow (this=0xbffff490) at TestWindow.cpp:25
> #4 0x080a1705 in main (argc=1, argv=0xbffff854) at Tester.cpp:8
> #5 0x4093e469 in __libc_start_main () from /lib/libc.so.6
> (gdb)
>
>
> PLEASE HELP ME!! I'm going MAD!!
> thanks in advance!!
>
>
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
--
-----------------------------------
Diego Fdez. Durán <diego goedi net>
Web: http://www.goedi.net
GPG ID: 90D266BB
-----------------------------------
Attachment:
signature.asc
Description: This is a digitally signed message part