开发者

Pointer combined in GTK

I have std::vetor with my structure it's being globally allocated in one file and then some structure is being passed to another function wich is placed in another file and then it's being passed again to another function which is placed yet in another file. Is it possible that pointer is somehow getting lost because I get acces violation durning callcing last function.

EDIT: When I passed pointer to structure instead of structure it worked.

I so don't get that board I can't edit my previous post... Anyway passing pointer also did not help >.> Maybe my callback function is wrong, I use event box to catch 2x click event on label:

void test(GtkWidget* widget, GdkEventButton * event, gpointer callback_data) 
{
    Profil* profil = (Profil*) callback_data;
    std::cout << profil->username << std::endl; //<--here it goes nuts
    if (event->type == GDK_2BUTTON_PRESS && event->button == 1) OknoPogody(profil);
}

void 开发者_JS百科Glowne_Okno(Profil profil) //<-- this function as argument accepts Profil structure

which is being passed before and in Glowne_Okno I call callback function:

g_signal_connect(G_OBJECT(Eventy[0]), "button_press_event",G_CALLBACK(test),&profil);

Before I also called: gtk_widget_set_events (Eventy[0], GDK_BUTTON_PRESS_MASK)


Your main problem is, that you pass pointer to local variable (arguments are local variables) to the signal, which will be called long after the function returns and destroys the structure in the process.

Since you are using C++, I'd strongly suggest you use the gtkmm C++ wrapper. That gives you typesafe method of connecting to signals and ability to use functors as handlers. I am not sure whether it (or rather it's utility sigc library) provides a way to bind arguments to the functors, but if it does not, it will work with boost::bind or std::bind from C++0x.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜