Combobox signal

Started by roccio, 30 January 2020, 08:56:08

roccio

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?

Kvaz1r

Could you provide minimal reproducible example?

roccio

With this I get no exception, but the value printed are not the one expected.


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;
}

Kvaz1r

Code works well for me.
Could you rebuild TGUI with current master and check it again? This commit seems related to your issue.

roccio

Will try asap. I have just downloaded the last binary from the Download section (0.8.6).

Thank you