Problem casting MouseEventArgs like in wiki

Artic_Ice83

05-10-2008 09:36:38

Hi!
i've seen the wiki and followed the first two tutorials, so i've added an event handler to the button and then specified the function:

void myFunction (const QuickGUI::EventArgs &args)
{
const QuickGUI::MouseEventArgs& mea = dynamic_cast<QuickGUI::MouseEventArgs&>(args);

if(mea.button == QuickGUI::MB_Left)
{
mFrameListener->exit();
}
}


but the compiler gives me an error in the line of the casting, telling me "cannot use 'dynamic_cast' to convert from 'const QuickGUI::EventArgs' to 'QuickGUI::MouseEventArgs &'".
what is wrong?

nullsquared

05-10-2008 13:34:58

You need a 'const' in the dynamic_cast<> part. You can't cast to a non-const type if the original is a const.

Also, you might want to use static_cast, it'll be faster. dynamic_cast is only really useful for pointers, since it can return NULL if the cast was outside a class hierarchy. Since you're using references, though, it can't return NULL, so there's really not much point in using it.

Artic_Ice83

05-10-2008 13:55:30

thanks for the hint!
now all works! :D

kungfoomasta

05-10-2008 23:15:02

Thanks for exposing the typo, I've updated the wiki. Also good to learn more about static vs dynamic casting. :)

Artic_Ice83

06-10-2008 14:35:13

i know that maybe this is not the right place to say that, but i have also noted that there is at least another error in the wiki, in the "getting started" tutorial: we have to include the file QuickGUIRoot.h and not QuickGUI.h. maybe another "error" is when passing some parameters to the button desc object: there aren't position and size properties...all is made by dimensions(if i'm not in error...).

kungfoomasta

06-10-2008 18:55:24

The Dimension class consists of a Size class and Point class, so they're all related. As for the wiki typos, everybody should be able to edit it right? :)

Artic_Ice83

06-10-2008 19:05:23

i didn't know...i'm not so practical with the wiki...

kungfoomasta

06-10-2008 19:25:43

I have fixed them both. Thanks again. :)

my.name

07-10-2008 20:48:15

=)