Combobox signal

  • 4 Replies
  • 66 Views
Combobox signal
« on: 30 January 2020, 08:56:08 »
Hi,
I have a combox and I want to connect a function on itemselected that pass the index of the selected item and not the text.

void ChangeColor(int index) { std::cout << index; std::endl;}

...

g_comboColor->connect("ItemSelected", ChangeColor);


This compiles well, but when I run the code I get an exception in SignalImpl.hll

const std::size_t offset = (sizeof...(UnboundArgs) > 0) ? signal.validateTypes({typeid(UnboundArgs)...}) : 0; (line 157)

What am I missing?

Re: Combobox signal
« Reply #1 on: 30 January 2020, 09:16:10 »
Could you provide minimal reproducible example?

Re: Combobox signal
« Reply #2 on: 30 January 2020, 09:22:36 »
With this I get no exception, but the value printed are not the one expected.

Code: [Select]
void ChangeColor(int val)
{
std::cout << val << std::endl;
}

int main()
{
sf::RenderWindow window(sf::VideoMode(SCREEN_W, SCREEN_H), "Aircraft configurator", sf::Style::Close);
window.setIcon(icon_image.width, icon_image.height, icon_image.pixel_data);

// init gui
tgui::Gui gui;
gui.setTarget(window);

tgui::ComboBox::Ptr combo = tgui::ComboBox::create();
combo->setPosition(100, 100);
combo->addItem("One");
combo->addItem("Two");
combo->connect("ItemSelected", ChangeColor);
gui.add(combo);

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed: window.close(); break;
}

gui.handleEvent(event);
}

window.clear(sf::Color::White);

gui.draw();

window.display();
}

return 0;
}

Re: Combobox signal
« Reply #3 on: 30 January 2020, 09:31:45 »
Code works well for me.
Could you rebuild TGUI with current master and check it again? This commit seems related to your issue.

Re: Combobox signal
« Reply #4 on: 30 January 2020, 09:33:22 »
Will try asap. I have just downloaded the last binary from the Download section (0.8.6).

Thank you