paragui-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [paragui-users] Problems with Signals


From: Ulf Lorenz
Subject: Re: [paragui-users] Problems with Signals
Date: Fri, 4 Mar 2005 00:49:32 +0100
User-agent: Mutt/1.5.6+20040907i

On Wed, Mar 02, 2005 at 11:04:09PM +0100, Sergio Ruiz wrote:
> Hi!!
> I am getting sick trying to figure out how to use the signals with paragui.
> 
> I have two questions that can save my live (and hopefully many others!!!).
> 
> 1)
> PG_Button* btnquit = app.GetWidget<PG_Button>("btnquit");
> btnquit->sigClick.connect(slot(handle_quit));
> 
> How can I pass arguments to the handle_quit function? Is it possible??
Another possibility that just came back to my mind:

Paragui signals can often take several arguments. Take the sigClick
signal of the PG_Button class. It can be connected to functions of
different kinds; in this case (I haven't tried it, but the code looks
quite straightforward there):

bool handle_click();
bool handle_click(PG_Pointer p);
bool handle_click(PG_Button* btn);
bool handle_click(PG_Button* btn, PG_Pointer p);

(PG_Pointer is just a synonym for void* via typedef). This scheme works
for more than one standard parameter (here the PG_Button) in the same
way (see pgsignals.h, a bit weird on the first glance, it takes some
minutes to step behind it).

The PG_Button* argument is always the button pressed. This also works in
similar fashions for other classes. E.g. with a menu callback, you can
get the selected menu item etc. The PG_Pointer (if you use one of these
variants) has to be supplied at the time of the connect call. By storing
it, you can also pass information. E.g. like this:

main.cpp:

bool handle_click(PG_Pointer status)
{
    mystatus = *(static_cast<int*>(status));
    ...
}

int main (...)
{
    int* status = new int;
    ...
    button->sigClick.connect(slot(handle_click, status));
}

Now by changing the status value, you can always pass some information
to the handle_click function.


Ulf

-- 
recursive:
            see recursive




reply via email to

[Prev in Thread] Current Thread [Next in Thread]