dotgnu-general
[Top][All Lists]
Advanced

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

[DotGNU]Re: Related to EventHandler


From: Marcus
Subject: [DotGNU]Re: Related to EventHandler
Date: Thu, 5 Dec 2002 20:52:59 -0600
User-agent: KMail/1.5

On Sunday 01 December 2002 10:28 am, address@hidden wrote:
> Yesterday I was coding a few little examples and in one of them, I
> needed to connect two signals to the same handler. The signals were from
> different events and I didn't know what to do for solving my problem.
> Can you help me?, please.
>
> Code:
>
> public class MiBoton : QPushButton {
>     public MiBoton(string a,QWidget b,string c) : base(a,b,c) {
>         mousePressEvent += new MousePressEvent (controladorEventos);
>         closeEvent += new CloseEvent (controladorEventos);
>     }
>     public void controladorEventos (QEvent e) {
>         Console.WriteLine ("Pulsado");
>     }
> }

Looking at QtSupport.cs, where event delegates are declared, shows why you're
having the problem:

Line 691> protected delegate void MousePressEvent (QMouseEvent e);

The delegate is declared to take a QMouseEvent, but your controladorEventos
takes a QEvent.

You appear to want the same event handler to be called for both pressing a
button and closing a dialog. However, the associate event structures are
different. Pressing a button (and other mouse event) uses a QMouseEvent,
which gives information specific to mouse actions, like the location of the
mouse. Closing a dialog uses a QCloseEvent, which doesn't have information
about mouse position and so forth. That is why they use different event
structures.

We could change the signature of the MousePressEvent to include a QEvent
instead of QMouseEvent, but that is probably not a good idea because even
handlers would then need to cast their QEvents to the appropriate type,
increasing runtime overhead and making a compile-time check impossible.

I'm not totally clear about what you're trying to do. Is it possible that
 what you really want to do would work betting using Qt signals and slots?
 Signals and slot style communication is usually used between widgets,
 whereas Qt events are usually thought of as communication between the window
 system and a widget.



reply via email to

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