Combobox event problems

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Ninja
Quite a regular
Quite a regular
Posts: 86
Joined: Sun Aug 20, 2006 11:42

Combobox event problems

Postby Ninja » Tue Sep 09, 2008 10:31

Hi Guys

okidoki thanks to ScriptKid who pointed me in the right direction for my last problem :D

i know have files from a folder being displayed in the combobox list :shock: :D

my problem is whats the correct way of seeing an EventSelectionChanged

as this will be needed to set up other things in the window according to which file is loaded

ie how to ->subscribeEvent

I thought it would be simmiler to the way listbox works

I tried a few ways but cant seem to get this to work one way was

Code: Select all

->subscribeEvent(CEGUI::ListboxTextItem::setSelected,
             CEGUI::Event::Subscriber(SetFile));


where setFile is a function for changing and refreshing the window

TIA

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Tue Sep 09, 2008 13:07

Hi,

you're welcome :)

For a combo box you need:

Code: Select all

subscribeEvent(CEGUI::ComboBox::EventListSelectionAccepted,
             CEGUI::Event::Subscriber(SetFile));


which is only called when the user actually closed the list by clicking an item.

HTH.
Check out my released snake game using Cegui!

Ninja
Quite a regular
Quite a regular
Posts: 86
Joined: Sun Aug 20, 2006 11:42

Postby Ninja » Wed Sep 10, 2008 18:49

hi ya


Thanks again ScriptKid

could you just confirm this will only work if pointing to a bool function
what i mean is the function SetFile is a int i get this error when compiling

int (__cdecl *)(const _TCHAR *,CEGUI::Combobox *)' : too few arguments for call


should i change this in function to a bool

sry if that sounds a dumb question :oops:

TIA

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Thu Sep 11, 2008 06:24

Hi,

i am not sure about the int/bool thing, but your error doesn't talk about the return type. It looks like the format of the function is wrong, it should be something like:

Code: Select all

bool MyApp::SetFile(const CEGUI::EventArgs& e)
{
  // Get combobox
  Combobox* combo = static_cast<Combobox*>(static_cast<const WindowEventArgs&>(e).window);
  // Get selected file
  String file = combo->getSelectedItem()->getText();
}


Good luck! :)
Check out my released snake game using Cegui!

Ninja
Quite a regular
Quite a regular
Posts: 86
Joined: Sun Aug 20, 2006 11:42

Postby Ninja » Thu Sep 11, 2008 16:18

hi ScriptKid


i've tried as above and various other ways but i keep getting

term does not evaluate to a function taking 1 arguments


Code: Select all

cb->subscribeEvent(CEGUI::Combobox::EventListSelectionChanged,      CEGUI::Event::Subscriber(&MyUI::SetFile));


i also tried

Code: Select all

cb->subscribeEvent(CEGUI::Combobox::EventListSelectionChanged,      CEGUI::Event::Subscriber(&MyUI::SetFile, this ));


which gives me this

global functions do not have 'this' pointers
'CEGUI::SubscriberSlot::SubscriberSlot' : no overloaded function takes 2 arguments


which from how i understand it is the expected errors from the searches i have done but i'am unable to fix this issue could you point me in the right direction please

TIA

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Postby Jamarr » Thu Sep 11, 2008 16:44

you need to show how you are declaring and defining MyUI::SetFile. It sounds like you did not define the function correctly.

Ninja
Quite a regular
Quite a regular
Posts: 86
Joined: Sun Aug 20, 2006 11:42

Postby Ninja » Thu Sep 11, 2008 17:00

hiya

if i understand you correctly

in my h file i have

Code: Select all

bool SetFile(const CEGUI::EventArgs& e);


then in the cpp i have

Code: Select all

bool MyUI::SetFile(const CEGUI::EventArgs& e)
{
  // Get combobox
   CEGUI::Combobox* combo = static_cast<CEGUI::Combobox*>(static_cast<const WindowEventArgs&>(e).window);
  // Get selected file
 String file = combo->getSelectedItem()->getText();
 
//todo
  return true;

User avatar
Kevin
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Mon May 26, 2008 15:44

Postby Kevin » Thu Sep 11, 2008 17:47

Hello,

The error

global functions do not have 'this' pointers


implies that you are calling

Code: Select all

cb->subscribeEvent(CEGUI::Combobox::EventListSelectionChanged,      CEGUI::Event::Subscriber(&MyUI::SetFile, this ));


from within a global function - in which case it is quite accurate... there is no 'this' pointer from within a global function.

Therefore, you need to call subscribeEvent(...) as above from within a function inside the MyUI class - such as the constructor.

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Postby Jamarr » Thu Sep 11, 2008 18:59

Yeah, I went off in the wrong direction there. Kevin is right - if you are not calling subscribeEvent() from a method within MyUI you cannot use the 'this' pointer. You can move the subscribeEvent() call into a MyUI method like the constructior, as Kevin mentioned. You can also just pass the actual pointer to the object instead of trying to pass 'this' in the global function you are using. Ex:

Code: Select all

void SomeGlobalFunction(CEGUI::Combobox* cb, MyUI* my_ui)
{
   cb->subscribeEvent(CEGUI::Combobox::EventListSelectionChanged, CEGUI::Event::Subscriber(&MyUI::SetFile, my_ui));
}
Last edited by Jamarr on Fri Sep 12, 2008 16:21, edited 1 time in total.

Ninja
Quite a regular
Quite a regular
Posts: 86
Joined: Sun Aug 20, 2006 11:42

Postby Ninja » Thu Sep 11, 2008 22:35

Thanks guys

thats got it to compile

just get an out of range error now on the string file ?

TIA


Return to “Help”

Who is online

Users browsing this forum: No registered users and 39 guests