Page 1 of 1

Combobox event problems

Posted: Tue Sep 09, 2008 10:31
by Ninja
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

Posted: Tue Sep 09, 2008 13:07
by scriptkid
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.

Posted: Wed Sep 10, 2008 18:49
by Ninja
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

Posted: Thu Sep 11, 2008 06:24
by scriptkid
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! :)

Posted: Thu Sep 11, 2008 16:18
by Ninja
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

Posted: Thu Sep 11, 2008 16:44
by Jamarr
you need to show how you are declaring and defining MyUI::SetFile. It sounds like you did not define the function correctly.

Posted: Thu Sep 11, 2008 17:00
by Ninja
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;

Posted: Thu Sep 11, 2008 17:47
by Kevin
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.

Posted: Thu Sep 11, 2008 18:59
by Jamarr
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));
}

Posted: Thu Sep 11, 2008 22:35
by Ninja
Thanks guys

thats got it to compile

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

TIA